Function that converts crop type to image style.

@param string $cropType
The croptype.

@return string
The associated image style.
332736
protected function cropToStyle($cropType) :string {
    $values = [
      'hero' => 'social_xx_large',
      'hero_small' => 'social_hero_small',
    ];

    switch ($cropType) {
      case 'hero_small':
        $this->isSmall = TRUE;
      default:
    }

    return $values[$cropType] ?? 'social_xx_large';
  }
1225439
private function applyFormatCrop(ImageInterface $image, array $cropParameters)
    {
        return $this->modifyAllLayers(
            $image,
            function(ImageInterface $layer) use ($cropParameters) {
                return $this->cropper->crop(
                    $layer,
                    $cropParameters['x'],
                    $cropParameters['y'],
                    $cropParameters['width'],
                    $cropParameters['height']
                );
            }
        );
    }
1085274
public function thumbnail($type)
    {
        // We take image from posts field
        $image = $this->attributes['image'];
        // We need to get extension type ( .jpeg , .png ...)
        $ext = pathinfo($image, PATHINFO_EXTENSION);
        // We remove extension from file name so we can append thumbnail type
        $name = rtrim($image, '.'.$ext);
        // We merge original name + type + extension
        return $name.'-'.$type.'.'.$ext;
    }
631330
public static function factory(StyleType $type): Style
    {
        return self::evaluate($type)->isInstanceOf(Style::class)->getValue();
    }
1161640
function convert($type)
    {
        if (in_array($type, array('gif','png','jpg'))){
            $this->_transforms_str.='convert('.$type.')';
            $this->_convert = $type;
        }
        return $this;
    }
1318802
private function getTypeXml($type)
    {
        if (!isset($this->styles[$type])) {
            return "<{$type}/>";
        }

        return sprintf(StyleXml::BORDER_TYPE_XML,
            $type, $this->styles[$type], $this->colors[$type], $type);
    }
463385
protected function formatType($type)
    {
        if (preg_match('/^(?:(.*)\.)?_(.*)$/', $type, $matches)) {
            if ($matches[1] !== '') {
                return sprintf("%s.%s[]", $matches[1], $matches[2]);
            } else {
                return $matches[2].'[]';
            }
        } else {
            return $type;
        }
    }
137357
protected function do_crop(\stdClass $src, $top, $left, $bottom, $right) {

		$dst = new \stdClass();
		$dst->width		= $src->width - $left - $right;
		$dst->height	= $src->height - $top - $bottom;
		$dst->resource	= imagecreatetruecolor($dst->width, $dst->height);

		if($this->mimeType == 'image/png' || $this->mimeType == 'image/gif') {
			imagealphablending($dst->resource, FALSE);
			imagesavealpha($dst->resource, TRUE);
		}

		imagecopy(
			$dst->resource,
			$src->resource,
			0, 0,
			$left, $top,
			$src->width - $left - $right, $src->height - $top - $bottom
		);

		return $dst;
	}
636279
private function schemaApiTypeToPropertyInfoType($type)
    {
        switch ($type) {

          case 'serial':
          case 'int':
              return new Type(Type::BUILTIN_TYPE_INT, true);

          case 'float':
          case 'numeric':
            return new Type(Type::BUILTIN_TYPE_FLOAT, true);

          case 'varchar':
          case 'text':
          case 'blob':
              return new Type(Type::BUILTIN_TYPE_STRING, true);
        }
    }
375790
public function getImageType()
    {
        $this->imageType = ($this->imageType === 'jpg') ? 'jpeg' : $this->imageType;
        $this->imageType = ( in_array($this->imageType, $this->imageTypes) ) ? $this->imageType : 'png';

        return $this->imageType;
    }
656211
private function _smartCrop($oldImage, $cropW, $cropH){
        $image = clone $oldImage;

        $this->resizeFit($image, 30, 30);

        $origW = $oldImage->getWidth();
        $origH = $oldImage->getHeight();
        $resizeW = $image->getWidth();
        $resizeH = $image->getHeight();

        $smallCropW = round(($resizeW / $origW) * $cropW);
        $smallCropH = round(($resizeH / $origH) * $cropH);

        $step = 1;

        for($y = 0; $y < $resizeH-$smallCropH; $y+=$step){
            for($x = 0; $x < $resizeW-$smallCropW; $x+=$step){
                $hist[$x.'-'.$y] = $this->_entropy($image->histogram(array(array($x, $y), array($smallCropW, $smallCropH))));
            }
            if($resizeW-$smallCropW <= 0){
                $hist['0-'.$y] = $this->_entropy($image->histogram(array(array(0, 0), array($smallCropW, $smallCropH))));
            }
        }
        if($resizeH-$smallCropH <= 0){
            $hist['0-0'] = $this->_entropy($image->histogram(array(array(0, 0), array($smallCropW, $smallCropH))));
        }

        asort($hist);
        end($hist);
        $pos = key($hist); // last key
        list($x, $y) = explode('-', $pos);
        $x = round($x*($origW / $resizeW));
        $y = round($y*($origH / $resizeH));

        return array($x,$y);
    }
928252
public static function doctype($type = 'xhtml1-trans')
	{
		if(static::$doctypes === null)
		{
			\Config::load('doctypes', true);
			static::$doctypes = \Config::get('doctypes', array());
		}

		if(is_array(static::$doctypes) and isset(static::$doctypes[$type]))
		{
			if($type == "html5")
			{
				static::$html5 = true;
			}
			return static::$doctypes[$type];
		}
		else
		{
			return false;
		}
	}
475693
protected function shopTypeToSourceType($shopType)
    {
        switch ($shopType) {
            case 'shop_order':
                return Source::Order;
            case 'shop_order_refund':
                return Source::CreditNote;
            default:
                $this->log->error('InvoiceManager::shopTypeToSourceType(%s): unknown', $shopType);
                return '';
        }
    }
236271
public function extension(String $type = 'jpeg', Bool $dot = true) : String
    {
        return image_type_to_extension(Helper::toConstant($type, 'IMAGETYPE_'), $dot);
    }
156752
public static function getClass($type)
    {
        if (!static::isAvailable($type)) {
            throw new \Exception(
                "Invalid image format '{$type}'. " .
                "Allowed formats are: " . implode(', ', static::available())
            );
        }

        $className = static::$typesMap[strtolower($type)];

        return new $className();
    }
644463
public function cropFromEdge($cropWidth, $cropHeight = null, $edge = 0)
        {
            if ($cropHeight === null) {
                $cropHeight = $cropWidth;
            }

            $cropWidth = ($this->_sourceWidth < $cropWidth) ? $this->_sourceWidth:$cropWidth;
            $cropHeight = ($this->_sourceHeight < $cropHeight) ? $this->_sourceHeight:$cropHeight;

            $cropX = intval(($this->_sourceWidth - $cropWidth) / 2);
            $cropY = intval(($this->_sourceHeight - $cropHeight) / 2);

            $top = (int) $edge | 12;
            if (14 == $top) {
                $cropY = 0;
            } elseif (13 == $top) {
                $cropY = $this->_sourceHeight - $cropHeight;
            }

            $left = ($edge >> 2);
            if (2 == $left) {
                $cropX = 0;
            } elseif (1 == $left) {
                $cropX = $this->_sourceWidth - $cropWidth;
            }

            return $this->crop($cropX, $cropY, $cropWidth, $cropHeight);
        }
776597
public function crop ($startX, $startY, $cropWidth, $cropHeight)
	{
		// validate input
		if (!is_numeric($startX))
		{
			throw new InvalidArgumentException('$startX must be numeric');
		}
		
		if (!is_numeric($startY))
		{
			throw new InvalidArgumentException('$startY must be numeric');
		}
		
		if (!is_numeric($cropWidth))
		{
			throw new InvalidArgumentException('$cropWidth must be numeric');
		}
		
		if (!is_numeric($cropHeight))
		{
			throw new InvalidArgumentException('$cropHeight must be numeric');
		}
		
		// do some calculations
		$cropWidth	= ($this->currentDimensions['width'] < $cropWidth) ? $this->currentDimensions['width'] : $cropWidth;
		$cropHeight = ($this->currentDimensions['height'] < $cropHeight) ? $this->currentDimensions['height'] : $cropHeight;
		
		// ensure everything's in bounds
		if (($startX + $cropWidth) > $this->currentDimensions['width'])
		{
			$startX = ($this->currentDimensions['width'] - $cropWidth);
			
		}
		
		if (($startY + $cropHeight) > $this->currentDimensions['height'])
		{
			$startY = ($this->currentDimensions['height'] - $cropHeight);
		}
		
		if ($startX < 0) 
		{
			$startX = 0;
		}
		
	    if ($startY < 0) 
		{
			$startY = 0;
		}
		
		// create the working image
		if (function_exists('imagecreatetruecolor'))
		{
			$this->workingImage = imagecreatetruecolor($cropWidth, $cropHeight);
		}
		else
		{
			$this->workingImage = imagecreate($cropWidth, $cropHeight);
		}
		
		$this->preserveAlpha();
		
		imagecopyresampled
		(
			$this->workingImage,
			$this->oldImage,
			0,
			0,
			$startX,
			$startY,
			$cropWidth,
			$cropHeight,
			$cropWidth,
			$cropHeight
		);
		
		$this->oldImage 					= $this->workingImage;
		$this->currentDimensions['width'] 	= $cropWidth;
		$this->currentDimensions['height'] 	= $cropHeight;
		
		return $this;
	}