Image placeholder
@param array $params
@param array $options
@return null|string
485127
public function placeholder(array $params, $options = [])
    {
        $placeholder = null;

        $width = (isset($params['width']) && is_numeric($params['width'])) ? $params['width'] : null;
        $height = (isset($params['height']) && is_numeric($params['height'])) ? $params['height'] : null;

        if (is_null($width) || is_null($height)) {
            throw new Exception('Wrong placeholder width or height');
        }

        if (isset($params['backgroundColor']) && $this->checkHexColor($params['backgroundColor'])) {
            $backgroundColor = $params['backgroundColor'];
        } else {
            $backgroundColor = $this->options['placeholder']['backgroundColor'];
        }

        if (isset($params['textColor']) && $this->checkHexColor($params['textColor'])) {
            $textColor = $params['textColor'];
        } else {
            $textColor = $this->options['placeholder']['textColor'];
        }

        $textSize = (isset($params['textSize']) && is_numeric($params['textSize'])) ? $params['textSize'] : $this->options['placeholder']['textSize'];

        $text = !empty($params['text']) ? $params['text'] : $this->options['placeholder']['text'];
        $random = isset($params['random']) ? $params['random'] : $this->options['placeholder']['random'];

        if ($this->options['placeholder']['type'] == self::PLACEHOLDER_TYPE_URL) {
            $placeholder = $this->urlPlaceholder($width, $height, $text, $backgroundColor, $textColor, $textSize,
                $random, $options);
        } elseif ($this->options['placeholder']['type'] == self::PLACEHOLDER_TYPE_JS) {
            $placeholder = $this->jsPlaceholder($width, $height, $text, $backgroundColor, $textColor, $random, $options);
        }

        return $placeholder;
    }
707582
public function assemble(array $params = [], array $options = [])
    {
        $elements              = [];
        $mergedParams          = array_replace($this->defaults, $params);
        $this->assembledParams = [];

        foreach ($this->exclude as $key) {
            unset($mergedParams[$key]);
        }

        if ($mergedParams) {
            foreach ($mergedParams as $key => $value) {
                if (is_array($value)) {
                    foreach ($value as $ivalue) {
                        $elements[] = rawurlencode($key) . $this->keyValueDelimiter . rawurlencode($ivalue);
                    }
                } else {
                    $elements[] = rawurlencode($key) . $this->keyValueDelimiter . rawurlencode($value);
                }
                $this->assembledParams[] = $key;
            }

            return $this->paramDelimiter . implode($this->paramDelimiter, $elements);
        }

        return '';
    }
1291221
public function outputImage($params = array())
    {
        $param_defaults = array(
            'width' => 120,
            'height' => 40,
            // 'length' => 6
        );
        $params = \array_merge($param_defaults, $params);
        $code = $this->generateCode($this->length);
        $font_size = $params['height'] * $this->font_scale;
        $image = @\imagecreate($params['width'], $params['height']) or die('Cannot initialize new GD image stream');
        // set the colors
        $color_bkg = \imagecolorallocate($image, 0, 0, 0);
        // $color_text = imagecolorallocate($image, 20, 40, 100);
        $color_text = \imagecolorallocate($image, 200, 200, 200);
        $color_noise = \imagecolorallocate($image, 150, 150, 150);
        // generate random dots in background
        for ($i=0; $i<($params['width']*$params['height'])/$this->dot_divisor; $i++) {
            \imagefilledellipse($image, \mt_rand(0, $params['width']), \mt_rand(0, $params['height']), 1, 1, $color_noise);
        }
        // generate random lines in background
        for ($i=0; $i<($params['width']*$params['height'])/$this->line_divisor; $i++) {
            \imageline($image, \mt_rand(0, $params['width']), \mt_rand(0, $params['height']), \mt_rand(0, $params['width']), \mt_rand(0, $params['height']), $color_noise);
        }
        // create textbox and add text
        $textbox = \imagettfbbox($font_size, 0, $this->font, $code); // or die('Error in imagettfbbox function');
        $x = ($params['width'] - $textbox[4])/2;
        $y = ($params['height'] - $textbox[5])/2;
        \imagettftext($image, $font_size, 0, $x, $y, $color_text, $this->font, $code); // or die('Error in imagettftext function');
        // output captcha image to browser
        \header('Last-Modified: '.\date('r'));
        \header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
        \header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
        \header('Content-Type: image/jpeg');
        \header('Pragma: no-cache');
        \imagejpeg($image);
        \imagedestroy($image);
    }
259063
protected function getMagentoOptions(array $options)
    {
        $result = array();
        foreach ($options as $value => $label) {
            $result[] = array(
                'value' => $value,
                'label' => $label,
            );
        }
        return $result;
    }
398434
public function trim($options) {
        if (isset($options['trim'])) return $this->trimPixels($options['trim']);
        if (isset($options['trim_perc'])) return $this->trimPerc($options['trim_perc']);
        return $this;
    }
25232
public function getThumb(array $data, array $options)
    {
        $options += array(
            'placeholder' => true,
            'imagestyle' => $this->config->get('image_style', 3));

        if (empty($options['entity_id'])) {
            return empty($options['placeholder']) ? '' : $this->getPlaceholder($options['imagestyle']);
        }

        $conditions = array(
            'entity' => $options['entity'],
            'entity_id' => $options['entity_id']
        );

        foreach ($this->getList($conditions) as $file) {
            if (isset($data[$options['entity'] . '_id']) && $file['entity_id'] == $data[$options['entity'] . '_id']) {
                return $this->getUrl($file['path'], $options['imagestyle']);
            }
        }

        return empty($options['placeholder']) ? '' : $this->getPlaceholder($options['imagestyle']);
    }
449341
private function watermark(array $params)
    {
        if (isset($params['posX']) && is_numeric($params['posX'])) {
            $posX = $params['posX'];
        } else {
            $posX = null;
        }

        if (isset($params['posY']) && is_numeric($params['posY'])) {
            $posY = $params['posY'];
        } else {
            $posY = null;
        }

        if (is_null($posX) || is_null($posY)) {
            throw new Exception('Wrong watermark coordinates');
        }

        if (isset($params['width']) && is_numeric($params['width'])) {
            $width = $params['width'];
        } else {
            $width = 0;
        }

        if (isset($params['height']) && is_numeric($params['height'])) {
            $height = $params['height'];
        } else {
            $height = 0;
        }

        $mode = isset($params['mode']) ? $params['mode'] : self::THUMBNAIL_OUTBOUND;

        if (isset($params['image']) && file_exists(Yii::getAlias($params['image']))) {
            $watermarkPath = Yii::getAlias($params['image']);
        } else {
            $watermarkPath = null;
        }

        if (is_null($watermarkPath)) {
            throw new Exception('Incorrect watermark image path');
        }

        $watermark = Image::getImagine()->open($watermarkPath);

        if ($this->image->getSize()->getHeight() < $posY + $watermark->getSize()->getHeight() ||
            $this->image->getSize()->getWidth() < $posX + $watermark->getSize()->getWidth()
        ) {
            throw new Exception('Cannot paste watermark of the given size at the specified position, as it moves outside of the image\'s box');
        }

        if ($width > 0 && $height > 0) {
            $height = $this->image->getSize()->getHeight();
            $width = $this->image->getSize()->getWidth();

            $watermark = $watermark->thumbnail(new Box($width, $height), $mode);
        }

        if ($posX < 0) {
            $posX = $this->image->getSize()->getWidth() - abs($posX) - $watermark->getSize()->getWidth();
        }

        if ($posY < 0) {
            $posY = $this->image->getSize()->getHeight() - abs($posY) - $watermark->getSize()->getHeight();
        }

        $position = new Point($posX, $posY);

        $this->image->paste($watermark, $position);
    }
335513
private function getRandomImage($type, $placeholder)
    {
        $pathKey = $type === 'image' ? 'file' : 'filename';

        if ($placeholder && ($filename = $this->fetchPlaceholder($placeholder))) {
            return [$pathKey => $filename, 'title' => 'placeholder', 'alt' => 'placeholder'];
        }

        $images = $this->getImageFiles();
        if (empty($images)) {
            return null;
        }
        $imageName = array_rand($images);
        $image = $images[$imageName];
        $title = $image->getFilename($image->getExtension());
        $title = ucwords(str_replace('-', ' ', $title));

        return [$pathKey => $image->getPath(), 'title' => $title, 'alt' => $title];
    }
1179282
public function serialize(GraphicQuestion $graphicQuestion, array $options = [])
    {
        $serialized = [
            'image' => $this->serializeImage($graphicQuestion),
            'pointers' => $graphicQuestion->getAreas()->count(),
            'pointerMode' => 'pointer', // the feature is not yet implemented, but the JSON schema already requires it
        ];

        if (in_array(Transfer::INCLUDE_SOLUTIONS, $options)) {
            $serialized['solutions'] = $this->serializeSolutions($graphicQuestion);
        }

        return $serialized;
    }
103617
public function getIdFromOptions(array $options) : string
    {
        $optionsResolver = new OptionsResolver();
        $optionsResolver->setRequired('id');

        $options = $optionsResolver->resolve($options);

        return $options['id'];
    }
231374
private function replacePreservingType(array $options, array $placeholders, array $values)
    {
        foreach ($options as $key => $option) {
            $plKey = array_search($option, $placeholders);
            if ($plKey !== false) {
                $options[$key] = $values[$plKey];
                continue;
            }
            $options[$key] = $this->replace($option, $placeholders, $values);
        }

        return $options;
    }
412885
public function imageSave($params)
    {
        if (is_array($params)) {
            imagejpeg($params['image'], $params['target'], 100);
            imagedestroy($params['image']);

            return true;
        } else {
            return false;
        }
    }
1215436
public static function create($params = null, $options = null)
    {
        self::_validateParams($params);
        if (!array_key_exists('subscription_item', $params)) {
            throw new Error\InvalidRequest("Missing subscription_item param in request", null);
        }
        $subscription_item = $params['subscription_item'];
        $url = "/v1/subscription_items/$subscription_item/usage_records";
        $request_params = $params;
        unset($request_params['subscription_item']);

        list($response, $opts) = static::_staticRequest('post', $url, $request_params, $options);
        $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
        $obj->setLastResponse($response);
        return $obj;
    }
1295465
public function getMetaImageFields($params = [])
    {
        // Define Placeholder:
        
        $placeholder = _t(__CLASS__ . '.DROPDOWNDEFAULT', '(default)');
        
        // Create Upload Field:
        
        $fields = [
            UploadField::create(
                'ImageMeta',
                $this->owner->fieldLabel('ImageMeta')
            )->setAllowedFileCategories('image')->setFolderName($this->owner->getMetaImageFolder())
        ];
        
        // Create Other Fields:
        
        $showAlign   = true;
        $showResize  = true;
        $showCaption = true;
        $showOptions = true;
        
        // Detect Simple Mode:
        
        if (isset($params['mode']) && $params['mode'] == 'simple') {
            $showAlign   = false;
            $showResize  = false;
            $showCaption = false;
            $showOptions = false;
        }
        
        // Detect Field Options:
        
        if (isset($params['showalign']) && $params['showalign']) {
            $showAlign = true;
        }
        
        if (isset($params['showresize']) && $params['showresize']) {
            $showResize = true;
        }
        
        if (isset($params['showcaption']) && $params['showcaption']) {
            $showCaption = true;
        }
        
        if (isset($params['showoptions']) && $params['showoptions']) {
            $showOptions = true;
        }
        
        // Create Caption Field:
        
        if ($showCaption) {
            
            $fields[] = HTMLEditorField::create(
                'ImageMetaCaption',
                $this->owner->fieldLabel('ImageMetaCaption')
            )->setRows(10);
            
        }
        
        // Create Alignment Field:
        
        if ($showAlign) {
            
            $fields[] = DropdownField::create(
                'ImageMetaAlignment',
                $this->owner->fieldLabel('ImageMetaAlignment'),
                ImageTools::singleton()->getAlignmentOptions()
            )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholder);
            
        }
        
        // Create Resize Fields:
        
        if ($showResize) {
            
            $fields = array_merge($fields, [
                DimensionsField::create(
                    'ImageMetaResize',
                    $this->owner->fieldLabel('ImageMetaResize')
                ),
                DropdownField::create(
                    'ImageMetaResizeMethod',
                    $this->owner->fieldLabel('ImageMetaResizeMethod'),
                    ImageTools::singleton()->getResizeMethods()
                )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholder)
            ]);
            
        }
        
        // Create Options Fields:
        
        if ($showOptions) {
            
            $fields = array_merge($fields, [
                DropdownField::create(
                    'ImageMetaLinked',
                    $this->owner->fieldLabel('ImageMetaLinked'),
                    $this->getToggleOptions()
                )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholder),
                DropdownField::create(
                    'ImageMetaHidden',
                    $this->owner->fieldLabel('ImageMetaHidden'),
                    $this->getToggleOptions()
                )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholder),
                DropdownField::create(
                    'ImageMetaCaptionHidden',
                    $this->owner->fieldLabel('ImageMetaCaptionHidden'),
                    $this->getToggleOptions()
                )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholder)
            ]);
            
        }
        
        // Answer Field Objects:
        
        return FieldList::create([
            FieldSection::create(
                'ImageMetaSection',
                $this->owner->fieldLabel('ImageMetaSection'),
                $fields
            )
        ]);
    }
753207
public function productDeleteByImage($image, $options=array()){

        $data = array();
        
        $data['image'] = base64_encode($image);

        $data = array_merge($data, $options);

        return $this->request($this->productDeleteUrl, $data);
    }
1060236
private function getFormat(array $options)
    {
        if (isset($options[self::PARAM_FORMAT])) {
            return $options[self::PARAM_FORMAT];
        } else {
            return $this->defaultFormat;
        }
    }
1078620
public function getContents(array $options=array()){
		$options['quality']=isset($options['quality'])?$options['quality']:80;
		ob_start();
		@imagejpeg($this->resource,null,$options['quality']);
		return ob_get_clean();
	}