function IMAGEN_tipo_normal() { $escalado = 'IMG/i/m/' . $_GET['ancho'] . '_' . $_GET['alto'] . '_' . $_GET['sha1']; $origen = 'IMG/i/' . $_GET['sha1']; $ancho = $_GET['ancho']; $alto = $_GET['alto']; if (@($ancho * $alto) > 562500) { die('La imagen solicitada excede el límite de este servicio'); } if (!file_exists($escalado)) { $im = new Imagick($origen); $im->setCompression(Imagick::COMPRESSION_JPEG); $im->setCompressionQuality(85); $im->setImageFormat('jpeg'); $im->stripImage(); $im->despeckleImage(); $im->sharpenImage(0.5, 1); //$im->reduceNoiseImage(0); $im->setInterlaceScheme(Imagick::INTERLACE_PLANE); $im->resizeImage($ancho, $alto, imagick::FILTER_LANCZOS, 1); $im->writeImage($escalado); $im->destroy(); } $im = new Imagick($escalado); $output = $im->getimageblob(); $outputtype = $im->getFormat(); $im->destroy(); header("Content-type: {$outputtype}"); header("Content-length: " . filesize($escalado)); echo $output; }
static function copyResizedImage($inputFile, $outputFile, $width, $height = null, $crop = true) { if (extension_loaded('gd')) { $image = new GD($inputFile); if ($height) { if ($width && $crop) { $image->cropThumbnail($width, $height); } else { $image->resize($width, $height); } } else { $image->resize($width); } return $image->save($outputFile); } elseif (extension_loaded('imagick')) { $image = new \Imagick($inputFile); if ($height && !$crop) { $image->resizeImage($width, $height, \Imagick::FILTER_LANCZOS, 1, true); } else { $image->resizeImage($width, null, \Imagick::FILTER_LANCZOS, 1); } if ($height && $crop) { $image->cropThumbnailImage($width, $height); } return $image->writeImage($outputFile); } else { throw new HttpException(500, 'Please install GD or Imagick extension'); } }
public function draw(OsuSignature $signature) { parent::draw($signature); if ($this->width != -1 || $this->height != -1) { $this->image->resizeImage($this->width == -1 ? $this->image->getImageWidth() : $this->width, $this->height == -1 ? $this->image->getImageHeight() : $this->height, 1, $this->filter); } $signature->getCanvas()->compositeImage($this->image, $this->composite, $this->x, $this->y); }
/** * Applies the image effect on an Imagick object. This function should be overridden by the effect. * @param \Imagick The image object to work with * @return \Imagick The new image object to use */ protected function executeFilterImagick(\Imagick $imageData) { $width = $imageData->getImageWidth(); $height = $imageData->getImageHeight(); $imageData->resizeImage(ceil($width / $this->pixelatePercentage), ceil($height / $this->pixelatePercentage), \Imagick::FILTER_LANCZOS, 0, false); $imageData->resizeImage($width, $height, \Imagick::FILTER_LANCZOS, 0, false); return $imageData; }
protected function _resize($width, $height) { if ($this->im->getNumberImages() > 1) { $this->im = $this->im->coalesceImages(); foreach ($this->im as $animation) { // $animation->setImagePage( $animation->getImageWidth(), $animation->getImageHeight(), 0, 0 ); $animation->resizeImage($width, $height, Imagick::FILTER_CUBIC, 0.5); } } else { if ($this->im->resizeImage($width, $height, Imagick::FILTER_CUBIC, 0.5)) { $this->width = $this->im->getImageWidth(); $this->height = $this->im->getImageHeight(); } } }
function writeNewpic($old, $new) { $maxsize = 600; $image = new Imagick($old); if ($image->getImageHeight() <= $image->getImageWidth()) { $image->resizeImage($maxsize, 0, Imagick::FILTER_LANCZOS, 1); } else { $image->resizeImage(0, $maxsize, Imagick::FILTER_LANCZOS, 1); } $image->setImageCompression(Imagick::COMPRESSION_JPEG); $image->setImageCompressionQuality(90); $image->stripImage(); $image->writeImage($new); $image->destroy(); }
public function createMissingThumbsAction() { $this->initCommonParams($this->getRequest()); $this->outputMessage('[light_cyan]Creating missing thumbs.'); $dbAdapter = $this->getServiceLocator()->get('dbAdapter'); $apartments = $dbAdapter->createStatement(' SELECT ai.*, a.`name` FROM `ga_apartment_images` ai LEFT JOIN `ga_apartments` a ON ai.`apartment_id` = a.`id` ')->execute(); foreach ($apartments as $apartment) { $this->outputMessage('[cyan]Looking into [light_blue]' . $apartment['name'] . '[cyan] images...'); for ($i = 1; $i <= 32; $i++) { if ($apartment['img' . $i]) { $imgPathComponents = explode('/', $apartment['img' . $i]); $originalFileName = array_pop($imgPathComponents); $originalFilePath = DirectoryStructure::FS_GINOSI_ROOT . DirectoryStructure::FS_IMAGES_ROOT . DirectoryStructure::FS_IMAGES_APARTMENT . $apartment['apartment_id'] . '/' . $originalFileName; $thumbFilePath = str_replace('_orig.', '_555.', $originalFilePath); if (!file_exists($originalFilePath)) { $this->outputMessage('[error] Original file for image ' . $i . ' is missing.'); } else { if (file_exists($thumbFilePath)) { $this->outputMessage('[light_blue] Thumb for image ' . $i . ' exists.'); } else { $thumb = new \Imagick($originalFilePath); $thumb->resizeImage(555, 370, \Imagick::FILTER_LANCZOS, 1); $thumb->writeImage($thumbFilePath); $this->outputMessage('[success] Added thumb for image ' . $i); } } } } } $this->outputMessage('Done!'); }
public function beforeSave($options = array()) { if (isset($this->data['Candidate']['image']) && is_array($this->data['Candidate']['image'])) { if (!empty($this->data['Candidate']['image']['size'])) { $im = new Imagick($this->data['Candidate']['image']['tmp_name']); $im->resizeImage(512, 512, Imagick::FILTER_CATROM, 1, true); $path = WWW_ROOT . 'media'; $fileName = str_replace('-', '/', String::uuid()) . '.jpg'; if (!file_exists($path . '/' . dirname($fileName))) { mkdir($path . '/' . dirname($fileName), 0777, true); } $im->writeImage($path . '/' . $fileName); if (file_exists($path . '/' . $fileName)) { $this->data['Candidate']['image'] = $fileName; } else { unset($this->data['Candidate']['image']); } } else { unset($this->data['Candidate']['image']); } } if (isset($this->data['Candidate']['name'])) { $this->data['Candidate']['name'] = str_replace(array('&bull;', '•', '‧', '.', '•', '..'), '.', $this->data['Candidate']['name']); } return parent::beforeSave($options); }
function renderOriginalImage() { $imagick = new \Imagick(realpath("../imagick/images/FineDetail.png")); $imagick->resizeImage($imagick->getImageWidth() * 4, $imagick->getImageHeight() * 4, \Imagick::FILTER_POINT, 1); \header('Content-Type: image/png'); echo $imagick->getImageBlob(); }
public static function thumbImage($imgPath, $width, $height, $blur = 1, $bestFit = 0, $cropZoom = 1) { $dir = dirname($imgPath); $imagick = new \Imagick(realpath($imgPath)); if ($imagick->getImageHeight() > $imagick->getImageWidth()) { $w = $width; $h = 0; } else { $h = $height; $w = 0; } $imagick->resizeImage($w, $h, $imagick::DISPOSE_UNDEFINED, $blur, $bestFit); $cropWidth = $imagick->getImageWidth(); $cropHeight = $imagick->getImageHeight(); if ($cropZoom) { $imagick->cropImage($width, $height, ($imagick->getImageWidth() - $width) / 2, ($imagick->getImageHeight() - $height) / 2); } $direct = 'thumbs/'; $pathToWrite = $dir . "/" . $direct; //var_dump($pathToWrite); if (!file_exists($pathToWrite)) { mkdir($pathToWrite, 0777, true); } $newImageName = 'thumb_' . basename($imgPath); //var_dump($newImageName); $imagick->writeImage($pathToWrite . 'thumb_' . basename($imgPath)); return $pathToWrite . $newImageName; }
public function makeThumb($path, $W = NULL, $H = NULL) { $image = new Imagick(); $image->readImage($ImgSrc); // Trasformo in RGB solo se e` il CMYK if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) { $image->transformImageColorspace(Imagick::COLORSPACE_RGB); } $image->profileImage('*', NULL); $image->stripImage(); $imgWidth = $image->getImageWidth(); $imgHeight = $image->getImageHeight(); if ((!$H || $H == null || $H == 0) && (!$W || $W == null || $W == 0)) { $W = $imgWidth; $H = $imgHeight; } elseif (!$H || $H == null || $H == 0) { $H = $W * $imgHeight / $imgWidth; } elseif (!$W || $W == null || $W == 0) { $W = $H * $imgWidth / $imgHeight; } $image->resizeImage($W, $H, Imagick::FILTER_LANCZOS, 1); /** Scrivo l'immagine */ $image->writeImage($path); /** IMAGE OUT */ header('X-MHZ-FLY: Nice job!'); header(sprintf('Content-type: image/%s', strtolower($image->getImageFormat()))); echo $image->getImageBlob(); $image->destroy(); die; }
public function resize($file, $size = array('width' => 100, 'height' => 100), $type = 'png', $fixed = false) { $image = new Imagick($this->file); $image->setBackgroundColor(new ImagickPixel('transparent')); $image->setImageFormat($type); if ($fixed === true) { $newWidth = $size['width']; $newHeight = $size['height']; } else { $imageprops = $image->getImageGeometry(); $width = $imageprops['width']; $height = $imageprops['height']; if ($width > $height) { $newHeight = $size['height']; $newWidth = $size['height'] / $height * $width; } else { $newWidth = $size['width']; $newHeight = $size['width'] / $width * $height; } } $image->resizeImage($newWidth, $newHeight, imagick::FILTER_LANCZOS, 1); $image->writeImage($file . '.' . $type); $image->clear(); $image->destroy(); }
/** * @param Asset $asset * @return string */ public function handleSave(Asset $asset) { $newImage = new \Imagick($asset->getUploadedFile()->getRealPath()); $asset->setHeight($newImage->getImageHeight()); $asset->setWidth($newImage->getImageWidth()); /** @var array $requiredImage */ foreach ($this->requiredImages as $requiredImage) { $newImage = new \Imagick($asset->getUploadedFile()->getRealPath()); $newFilename = pathinfo($asset->getFilename(), PATHINFO_FILENAME) . '-' . $requiredImage['name'] . '.' . pathinfo($asset->getFilename(), PATHINFO_EXTENSION); $imageWidth = $newImage->getImageWidth(); $imageHeight = $newImage->getImageHeight(); $isLandscapeFormat = $imageWidth > $imageHeight; $orientation = $newImage->getImageOrientation(); $newImage->setCompression(\Imagick::COMPRESSION_JPEG); $newImage->setImageCompressionQuality($requiredImage['quality']); if ($isLandscapeFormat) { $desiredWidth = $requiredImage['long']; $newImage->resizeImage($desiredWidth, 0, \Imagick::FILTER_LANCZOS, 1); if (isset($requiredImage['short']) && boolval($requiredImage['crop']) == true) { $newImage->cropImage($desiredWidth, $requiredImage['short'], 0, 0); } else { $newImage->resizeImage(0, $requiredImage['short'], \Imagick::FILTER_LANCZOS, 1); } } else { $desiredHeight = $requiredImage['long']; $newImage->resizeImage(0, $desiredHeight, \Imagick::FILTER_LANCZOS, 1); if (isset($requiredImage['short']) && boolval($requiredImage['crop']) == true) { $newImage->cropImage($requiredImage['short'], $desiredHeight, 0, 0); } else { $newImage->resizeImage($requiredImage['short'], 0, \Imagick::FILTER_LANCZOS, 1); } } /** * This unfortunately kills the orientation. Leave EXIF-Info for now. * * $newImage->stripImage(); * $newImage->setImageOrientation($orientation); */ $this->assetStorage->uploadFile($newFilename, $newImage); $subAsset = new SubAsset(); $subAsset->setFilename($newFilename); $subAsset->setType($requiredImage['name']); $subAsset->setHeight($newImage->getImageHeight()); $subAsset->setWidth($newImage->getImageWidth()); $asset->addSubAsset($subAsset); } }
public function getOriginalImageResponse() { $imagePath = $this->getOriginalImagePath(); $imagick = new \Imagick(realpath($imagePath)); $imagick->resizeImage($imagick->getImageWidth() * 4, $imagick->getImageHeight() * 4, \Imagick::FILTER_POINT, 1); header('Content-Type: image/png'); echo $imagick->getImageBlob(); }
/** * {@inheritdoc} * * @return ImageInterface */ public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDEFINED) { try { $this->imagick->resizeImage($size->getWidth(), $size->getHeight(), $this->getFilter($filter), 1); } catch (\ImagickException $e) { throw new RuntimeException('Resize operation failed', $e->getCode(), $e); } return $this; }
/** * Returns a resized \Imagick object * * If you want to know more on the various methods available to resize an * image, check out this link : @link https://stackoverflow.com/questions/8517304/what-the-difference-of-sample-resample-scale-resize-adaptive-resize-thumbnail-im * * @param \Imagick $bp * @param int $maxX * @param int $maxY * * @return \Imagick */ private function resize($bp, $maxX, $maxY) { list($previewWidth, $previewHeight) = array_values($bp->getImageGeometry()); // We only need to resize a preview which doesn't fit in the maximum dimensions if ($previewWidth > $maxX || $previewHeight > $maxY) { // TODO: LANCZOS is the default filter, CATROM could bring similar results faster $bp->resizeImage($maxX, $maxY, imagick::FILTER_LANCZOS, 1, true); } return $bp; }
function saveMe($checkUserData = true, $output = false) { if ($this->A("ContentImage") != "") { $path = Util::getRootPath() . "specifics/" . $this->A("ContentImage"); $image = new Imagick($path); $imageSmall = Util::getRootPath() . "specifics/" . str_replace(basename($this->A("ContentImage")), "small/" . basename($this->A("ContentImage")), $this->A("ContentImage")); $imageBig = Util::getRootPath() . "specifics/" . str_replace(basename($this->A("ContentImage")), "big/" . basename($this->A("ContentImage")), $this->A("ContentImage")); $image->resizeImage(0, 550, Imagick::FILTER_LANCZOS, 1); if (!$image->writeImage($imageBig)) { Red::alertD("Das große Vorschaubild kann nicht erstellt werden!"); } $image->resizeImage(150, 0, Imagick::FILTER_LANCZOS, 1); if (!$image->writeImage($imageSmall)) { Red::alertD("Das kleine Vorschaubild kann nicht erstellt werden!"); } $image->destroy(); } parent::saveMe($checkUserData, $output); }
function imgThumbs($img) { if (file_exists($img)) { $imagen = new Imagick($img); if ($imagen->getImageHeight() <= $imagen->getImageWidth()) { $imagen->resizeImage(120, 0, Imagick::FILTER_LANCZOS, 1); } else { $imagen->resizeImage(0, 120, Imagick::FILTER_LANCZOS, 1); } $imagen->setImageCompression(Imagick::COMPRESSION_JPEG); $imagen->setImageCompressionQuality(75); $imagen->stripImage(); $imagen->writeImage($img); $imagen->destroy(); chmod($img, 0777); return true; } else { return false; } }
public function processBinaryImageData(string $binaryImageData) : string { $this->validateImageDimensions($this->width, $this->height); $imagick = new \Imagick(); try { $imagick->readImageBlob($binaryImageData); } catch (\ImagickException $e) { throw new InvalidBinaryImageDataException($e->getMessage()); } $imagick->resizeImage($this->width, $this->height, \Imagick::FILTER_LANCZOS, 1); return $imagick->getImageBlob(); }
/** * Resize and crop the image so it dimensions matches $targetWidth and $targetHeight * * @param int $targetWidth * @param int $targetHeight * @return boolean|\Imagick */ public function resizeAndCrop($targetWidth, $targetHeight) { // First get the size that we can use to safely trim down the image without cropping any sides $crop = $this->getSafeResizeOffset($this->originalImage, $targetWidth, $targetHeight); // Resize the image $this->originalImage->resizeImage($crop['width'], $crop['height'], $this->getFilter(), $this->getBlur()); // Get the offset for cropping the image further $offset = $this->getSpecialOffset($this->originalImage, $targetWidth, $targetHeight); // Crop the image $this->originalImage->cropImage($targetWidth, $targetHeight, $offset['x'], $offset['y']); return $this->originalImage; }
function loadDir($path) { if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if ($file != "." and $file != "..") { //skip . and .. if (is_file($path . '/' . $file)) { $tmpFile = trim($file); $ext = pathinfo($file, PATHINFO_EXTENSION); $File = pathinfo($file, PATHINFO_FILENAME); $valid_exts = array('jpeg', 'JPEG', 'jpg', 'JPG', 'png', 'PNG', 'gif', 'GIF'); $sizes = array('f' => 45, 't' => 92, 's' => 120, 'm' => 225, 'l' => 300); //required sizes in WxH ratio if (in_array($ext, $valid_exts)) { // if file is image then process it! foreach ($sizes as $w => $h) { $image = new Imagick(); $image->readImage($path . '/' . $tmpFile); $imgWidth = $image->getImageWidth(); $imgHeight = $image->getImageHeight(); $image->resizeImage($h, $h, Imagick::FILTER_LANCZOS, 1); // resize from array sizes $fileName .= $File . '_' . $w . '.' . $ext; //create the image filaname $image->writeImage($path . '/' . $fileName); $tempFileName = $path . '/' . $fileName; $arrayfiles[] = $tempFileName; $custWidth = $image->getImageWidth(); $custHeight = $image->getImageHeight(); echo "[ Original dimension : {$imgWidth} x {$imgHeight} ] [ Custom dimension : {$custWidth} x {$custHeight} ] Output image location: <a href='{$tempFileName}' style='text-decoration:none'> " . $tempFileName . "</a> "; echo "<img class='img' src='{$tempFileName}' /></br>"; $w = ''; $h = ''; $fileName = ''; $image->clear(); $image->destroy(); } //end foreach sizes } } if (is_dir($path . '/' . $file)) { echo '</br> <div style="height:0;width:1200px;border:0;border-bottom:2px;border-style: dashed;border-color: #000000"></div><span style="font-weight:bold; font-size:14px; color:red ">Directory Name: '; echo $path . "/" . $file; echo '</span><div style="height:0;width:1200px;border:0;border-bottom:2px;border-style: dashed;border-color: #000000"></div></br>'; loadDir($path . '/' . $file); } } } // end while } // end handle }
function createMask($firstPicture, $twoPicture, $mask, $maskX, $masky, $x, $y) { $img = new Imagick($firstPicture); $mask = new Imagick($mask); $width = $mask->getImageWidth(); $height = $mask->getImageHeight(); $img->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1); $img->compositeImage($mask, Imagick::COMPOSITE_DSTIN, $maskX, $masky); header("Content-Type: image/jpeg"); $img2 = new Imagick('goodMasks.jpg'); $img2->compositeImage($img, $img->getImageCompose(), $x, $y); echo $img2; }
/** * Resizes the image * * @param integer $new_x New width * @param integer $new_y New height * @param mixed $options Optional parameters * <ul> * <li>'scaleMethod': "pixel" or "smooth"</li> * </ul> * * @return bool|PEAR_Error TRUE or PEAR_Error object on error * @access protected */ function _resize($new_x, $new_y, $options = null) { try { $scaleMethod = $this->_getOption('scaleMethod', $options, 'smooth'); $blur = $scaleMethod == 'pixel' ? 0 : 1; $this->imagick->resizeImage($new_x, $new_y, imagick::FILTER_UNDEFINED, $blur); } catch (ImagickException $e) { return $this->raiseError('Could not resize image.', IMAGE_TRANSFORM_ERROR_FAILED); } $this->new_x = $new_x; $this->new_y = $new_y; return true; }
/** * {@inheritdoc} */ public function resize(BoxInterface $size, $filter = ImageInterface::FILTER_UNDEFINED) { static $supportedFilters = array(ImageInterface::FILTER_UNDEFINED => \Imagick::FILTER_UNDEFINED, ImageInterface::FILTER_BESSEL => \Imagick::FILTER_BESSEL, ImageInterface::FILTER_BLACKMAN => \Imagick::FILTER_BLACKMAN, ImageInterface::FILTER_BOX => \Imagick::FILTER_BOX, ImageInterface::FILTER_CATROM => \Imagick::FILTER_CATROM, ImageInterface::FILTER_CUBIC => \Imagick::FILTER_CUBIC, ImageInterface::FILTER_GAUSSIAN => \Imagick::FILTER_GAUSSIAN, ImageInterface::FILTER_HANNING => \Imagick::FILTER_HANNING, ImageInterface::FILTER_HAMMING => \Imagick::FILTER_HAMMING, ImageInterface::FILTER_HERMITE => \Imagick::FILTER_HERMITE, ImageInterface::FILTER_LANCZOS => \Imagick::FILTER_LANCZOS, ImageInterface::FILTER_MITCHELL => \Imagick::FILTER_MITCHELL, ImageInterface::FILTER_POINT => \Imagick::FILTER_POINT, ImageInterface::FILTER_QUADRATIC => \Imagick::FILTER_QUADRATIC, ImageInterface::FILTER_SINC => \Imagick::FILTER_SINC, ImageInterface::FILTER_TRIANGLE => \Imagick::FILTER_TRIANGLE); if (!array_key_exists($filter, $supportedFilters)) { throw new InvalidArgumentException('Unsupported filter type'); } try { $this->imagick->resizeImage($size->getWidth(), $size->getHeight(), $supportedFilters[$filter], 1); } catch (\ImagickException $e) { throw new RuntimeException('Resize operation failed', $e->getCode(), $e); } return $this; }
function resizeImage($imagePath) { // Max vert or horiz resolution $maxsize = 300; // create new Imagick object $image = new Imagick($imagePath); // Resizes to whichever is larger, width or height if ($image->getImageHeight() <= $image->getImageWidth()) { // Resize image using the lanczos resampling algorithm based on width $image->resizeImage($maxsize, 0, Imagick::FILTER_LANCZOS, 1); } else { // Resize image using the lanczos resampling algorithm based on height $image->resizeImage(0, $maxsize, Imagick::FILTER_LANCZOS, 1); } // Set to use jpeg compression $image->setImageCompression(Imagick::COMPRESSION_JPEG); // Set compression level (1 lowest quality, 100 highest quality) $image->setImageCompressionQuality(75); // Strip out unneeded meta data $image->stripImage(); return $image; }
/** * Resize current image. * * @see Horde_Image_im::resize() * * @return void */ public function resize($width, $height, $ratio = true, $keepProfile = false) { try { if ($keepProfile) { $this->_imagick->resizeImage($width, $height, $ratio); } else { $this->_imagick->thumbnailImage($width, $height, $ratio); } } catch (ImagickException $e) { throw new Horde_Image_Exception($e); } $this->clearGeometry(); }
/** * Converts the specified image to the specified width and height and the specified extension. * * @param string $sourceImagePath * @param int $width * @param int $height * @param string $newExtension, optional */ public static function convertTo($sourceImagePath, $width, $height, $newExtension = '') { if (!class_exists('Imagick', false)) { throw new Zend_Exception('Class \'Imagick\' not found.'); } $image = new Imagick($sourceImagePath); $destImagePath = $sourceImagePath; if (!empty($newExtension)) { $destImagePath = substr($destImagePath, 0, strrpos($destImagePath, '.') + 1) . $newExtension; $image->setImageFormat($newExtension); } $image->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1); $image->writeImage($destImagePath); }
public function processBinaryImageData(string $binaryImageData) : string { $this->validateImageDimensions($this->width, $this->height); $this->validateBackgroundColor(); $image = new \Imagick(); try { $image->readImageBlob($binaryImageData); } catch (\ImagickException $e) { throw new InvalidBinaryImageDataException($e->getMessage()); } $image->resizeImage($this->width, $this->height, \Imagick::FILTER_LANCZOS, 1, true); $canvas = $this->inscribeImageIntoCanvas($image); return $canvas->getImageBlob(); }
function image($product_id = 0, $view = 'front', $index = 0) { $product_id = (int) $product_id; $index = (int) $index; if ($product_id == 0) { return false; } $this->load->driver('cache'); if ($this->cache->file->get('product-img-' . $product_id . '-' . $view . '-' . $index) == false) { // load product design $this->load->model('product_m'); $product = $this->product_m->getProductDesign($product_id); if (count($product)) { $this->load->helper('product'); $help_product = new helperProduct(); $design = $help_product->getDesign($product); } else { return false; } $design = json_decode(json_encode($design), true); if (empty($design[$view][$index])) { return false; } $string = str_replace("'", '"', $design[$view][$index]); $string = str_replace('px"', '"', $string); $img = new Imagick(); $img->newImage(500, 500, new ImagickPixel('transparent')); $img->setImageFormat('png'); $design = json_decode($string, true); $n = count($design) - 1; for ($i = $n; $i >= 0; $i--) { $image = $design[$i]; if ($image['id'] == 'area-design') { continue; } $file = ROOTPATH . DS . str_replace('/', DS, $image['img']); $newfile = new Imagick($file); $newfile->resizeImage($image['width'], $image['height'], Imagick::FILTER_LANCZOS, 1); $img->compositeImage($newfile, Imagick::COMPOSITE_DEFAULT, $image['left'], $image['top']); } $thumbnail = $img->getImageBlob(); $this->cache->file->save('product-img-' . $product_id . '-' . $view . '-' . $index, base64_encode($thumbnail), 300000); } else { $img = $this->cache->file->get('product-img-' . $product_id . '-' . $view . '-' . $index); $thumbnail = base64_decode($img); } header("Content-Type: image/png"); echo $thumbnail; }