<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('Do', function ($Call) { if (isset($Call['Current Image']['Thumb']) && !empty($Call['Current Image']['Data'])) { try { $GImage = new Gmagick(); $GImage->readimageblob($Call['Current Image']['Data']); /* $GImage->setCompressionQuality($Call['Image']['Quality']);*/ if (!isset($Call['Current Image']['Height'])) { $Call['Current Image']['Height'] = ceil($Call['Current Image']['Width'] / $GImage->getimagewidth() * $GImage->getimageheight()); } if (!isset($Call['Current Image']['Width'])) { $Call['Current Image']['Width'] = ceil($Call['Current Image']['Height'] / $GImage->getimageheight() * $GImage->getimagewidth()); } $GImage->cropthumbnailimage($Call['Current Image']['Width'], $Call['Current Image']['Height']); $Call['Current Image']['Data'] = $GImage->getImageBlob(); } catch (Exception $e) { F::Log($e->getMessage(), LOG_ERR); F::Log($Call['Current Image'], LOG_ERR); } } return $Call; });
/** * Apply transformations on image * * @param string $source Source image * @param array $params Transformations and parameters * @param string $store Temporary store on disk * * @return string */ public function transform($source, $params, $store = null) { try { $image = new \Gmagick(); $image->readImage($source); if (isset($params['negate'])) { $this->canNegate(); } if (isset($params['rotate'])) { $image->rotateImage('#000', $params['rotate']['angle']); } if (isset($params['crop'])) { $image->cropImage($params['crop']['width'], $params['crop']['height'], $params['crop']['x'], $params['crop']['y']); } if (isset($params['contrast'])) { $this->canContrast(); } if (isset($params['brightness'])) { $value = (int) $params['brightness']; $brightness = null; if ($value <= 0) { $brightness = $value + 100; } else { $brightness = $value * 3 + 100; } $image->modulateImage($brightness, 100, 100); } $ret = null; if ($store !== null) { $ret = $image->writeImage($store); } else { $ret = $image->getImageBlob(); } $image->destroy(); return $ret; } catch (\GmagickException $e) { $image->destroy(); throw new \RuntimeException($e->getMessage()); } }