function mkbilder() { $this->err->write('mkbilder', 'IN'); if (!class_exists("Imagick")) { $this->err->out("Imagick-Extention nicht installiert", true); return false; } $handle = new Imagick(); if (!$handle->readImage("./tmp/tmp.file_org")) { return false; } $d = $handle->getImageGeometry(); if ($d["width"] < $d["height"]) { $faktor = $d["height"] / $d["width"]; } else { $faktor = $d["width"] / $d["height"]; } $thumbheight = floor($this->thumbwidth * $faktor); $handle->thumbnailImage($this->thumbwidth, $thumbheight); $rc = $handle->writeImage("./tmp/tmp.file_thumb"); $handle->readImage("./tmp/tmp.file_org"); $popupheight = floor($this->popupwidth * $faktor); $handle->thumbnailImage($this->popupwidth, $popupheight); $rc = $handle->writeImage("./tmp/tmp.file_popup"); $handle->readImage("./tmp/tmp.file_org"); $infoheight = floor($this->infowidth * $faktor); $handle->thumbnailImage($this->infowidth, $infoheight); $rc = $handle->writeImage("./tmp/tmp.file_info"); return $rc; }
function post_resource($data) { if ($this->storage->dir->exists) { return so_output::conflict('Image already exists'); } $this->storage->dir->exists = true; $image = new \Imagick((string) $data['file']); $image->writeImage((string) $this->fileOrinal); $size = $image->getImageGeometry(); if ($size['width'] > 800 or $size['height'] > 600) { $image->adaptiveResizeImage(800, 600, true); } $image->writeImage((string) $this->fileMaximal); $size = $image->getImageGeometry(); if ($size['width'] > 100 or $size['height'] > 100) { $image->adaptiveResizeImage(100, 100, true); } $image->writeImage((string) $this->filePreview); return so_output::ok()->content($this->model); }
function get_image_size($fn) { // try gd if (function_exists('getimagesize')) { $ret = @getimagesize($fn); if ($ret !== false) { return array('width' => $ret[0], 'height' => $ret[1], 'mime' => $ret['mime']); } } // try imagemagick if (extension_loaded('imagick')) { try { $im = new Imagick($fn); return $im->getImageGeometry(); } catch (Exception $e) { } } // XXX: use bin? return false; }
public function load($path) { if (file_exists($path)) { $this->originImage = new \Imagick($path); $this->originGeo = $this->originImage->getImageGeometry(); print_r($this->originGeo); } else { throw new \Exception("File {$path} doesn't exists", 404); } }
function imagick_thumbnail($image, $timage, $ext, $thumbnail_name, $imginfo) { try { $imagick = new Imagick(); $fullpath = "./" . $this->thumbnail_path . "/" . $timage[0] . "/" . $thumbnail_name; if ($ext == "gif") { $imagick->readImage($image . '[0]'); } else { $imagick->readImage($image); } $info = $imagick->getImageGeometry(); $this->info[0] = $info['width']; $this->info[1] = $info['height']; $imagick->thumbnailImage($this->dimension, $this->dimension, true); if ($ext == "png" || $ext == "gif") { $white = new Imagick(); $white->newImage($this->dimension, $this->dimension, "white"); $white->compositeimage($image, Imagick::COMPOSITE_OVER, 0, 0); $white->writeImage($fullpath); $white->clear(); } else { $imagick->writeImage($fullpath); } $imagick->clear(); } catch (Exception $e) { echo "Unable to load image." . $e->getMessage(); return false; } return true; }
public function getSizesWhen($sizeString) { $size = $this->getModule()->parseSize($sizeString); if (!$size) { throw new \Exception('Bad size..'); } if ($this->getModule()->graphicsLibrary == 'Imagick') { $image = new \Imagick($this->getPathToOrigin()); $sizes = $image->getImageGeometry(); } else { $image = new \abeautifulsite\SimpleImage($this->getPathToOrigin()); $sizes['width'] = $image->get_width(); $sizes['height'] = $image->get_height(); } $imageWidth = $sizes['width']; $imageHeight = $sizes['height']; $newSizes = []; if (!$size['width']) { $newWidth = $imageWidth * ($size['height'] / $imageHeight); $newSizes['width'] = intval($newWidth); $newSizes['heigth'] = $size['height']; } elseif (!$size['height']) { $newHeight = intval($imageHeight * ($size['width'] / $imageWidth)); $newSizes['width'] = $size['width']; $newSizes['heigth'] = $newHeight; } return $newSizes; }
public function post() { if ($this->validate()) { $image = new PhotoActiveRecord(); $image->userId = Yii::$app->user->identity->id; $image->name = $this->name . ''; $image->photo = file_get_contents($this->file->tempName); $image->posted = date('Y-m-d H-i-s'); $imagick = new \Imagick(); $imagick->readImageBlob($image->photo); $size = $imagick->getImageGeometry(); if ($size['width'] > 800) { foreach ($imagick as $frame) { $frame->thumbnailImage(800, 0); } } $image->thumbnail = $imagick->getImagesBlob(); if (!$image->save()) { return false; } $tags = split(',', $this->tags); foreach ($tags as $item) { if ($item != '') { $tag = new TagsActiveRecord(); $tag->photo = $image->id; $tag->tag = trim($item); if (!$tag->save()) { return false; } } } return true; } return false; }
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(); }
/** * Get the cropping offset for the image based on the center of the image * * @param \Imagick $image * @param int $targetWidth * @param int $targetHeight * @return array */ protected function getCenterOffset(\Imagick $image, $targetWidth, $targetHeight) { $size = $image->getImageGeometry(); $originalWidth = $size['width']; $originalHeight = $size['height']; $goalX = (int) (($originalWidth - $targetWidth) / 2); $goalY = (int) (($originalHeight - $targetHeight) / 2); return array('x' => $goalX, 'y' => $goalY); }
function isWQXGAFile($filename) { try { $image = new Imagick($filename); $data = $image->getImageGeometry(); } catch (ImagickException $e) { } return !empty($data) && $data['width'] == 2560 && $data['height'] == 1600; }
private function inscribeImageIntoCanvas(\Imagick $image) : \Imagick { $dimensions = $image->getImageGeometry(); $x = (int) round(($this->width - $dimensions['width']) / 2); $y = (int) round(($this->height - $dimensions['height']) / 2); $canvas = new \Imagick(); $canvas->newImage($this->width, $this->height, $this->backgroundColor, $image->getImageFormat()); $canvas->compositeImage($image, \Imagick::COMPOSITE_OVER, $x, $y); return $canvas; }
/** * 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 render() { $imagick = new \Imagick(realpath($this->imageControl->getImagePath())); $output = "The values of getImageGeometry for the image below are:\n"; foreach ($imagick->getImageGeometry() as $key => $value) { $output .= "{$key} : {$value}\n"; } $output = nl2br($output); $output .= $this->renderImageURL(); return $output; }
/** * This function compared two images * * @param Imagick $image1 * @param Imagick $image2 * @return ComparisonResult */ public function compare(\Imagick $image1, \Imagick $image2) { $imagick1Size = $image1->getImageGeometry(); $imagick2Size = $image2->getImageGeometry(); $maxWidth = max($imagick1Size['width'], $imagick2Size['width']); $maxHeight = max($imagick1Size['height'], $imagick2Size['height']); $image1->extentImage($maxWidth, $maxHeight, 0, 0); $image2->extentImage($maxWidth, $maxHeight, 0, 0); $result = $image1->compareImages($image2, \Imagick::METRIC_MEANSQUAREERROR); $result[0]->setImageFormat('png'); return new ComparisonResult(round($result[1] * 100, 2), $image1, $image2, $result[0]); }
public function getSizes() { $sizes = false; if ($this->getModule()->graphicsLibrary == 'Imagick') { $image = new \Imagick($this->getPathToOrigin()); $sizes = $image->getImageGeometry(); } else { $image = new \abeautifulsite\SimpleImage($this->getPathToOrigin()); $sizes['width'] = $image->get_width(); $sizes['height'] = $image->get_height(); } return $sizes; }
/** * Returns the height and width of the current image data. * * @return array An hash with 'width' containing the width, * 'height' containing the height of the image. */ public function getDimensions() { if ($this->_height == 0 && $this->_width == 0) { try { $size = $this->_imagick->getImageGeometry(); } catch (ImagickException $e) { return array('width' => 0, 'height' => 0); } $this->_height = $size['height']; $this->_width = $size['width']; } return array('width' => $this->_width, 'height' => $this->_height); }
function perspective($firstPicture, $twoPicture, $pointTLX, $pointTLY, $pointBLX, $pointBLY, $pointTRX, $pointTRY, $pointBRX, $pointBRY) { $imagick = new \Imagick(realpath($firstPicture)); $points = array(array('x' => $pointTLX, 'y' => $pointTLY), array('x' => $pointBLX, 'y' => $pointBLY), array('x' => $pointTRX, 'y' => $pointTRY), array('x' => $pointBRX, 'y' => $pointBRY)); $geometry = $imagick->getImageGeometry(); $controlPoints = array(0, 0, $points[0]['x'], $points[0]['y'], 0, $geometry['height'], $points[1]['x'], $points[1]['y'], $geometry['width'], 0, $points[2]['x'], $points[2]['y'], $geometry['width'], $geometry['height'], $points[3]['x'], $points[3]['y']); $imagick->distortImage(Imagick::DISTORTION_AFFINE, $controlPoints, true); header("Content-Type: image/jpg"); $img2 = new Imagick($twoPicture); $imagick->thumbnailImage(140, 140); //$img2->compositeImage($imagick, $imagick->getImageCompose(), 155, 290); $img2->compositeImage($imagick, $imagick->getImageCompose(), $pointTLX, $pointTRY); echo $img2; }
/** * Helper function to build a link for jQuery Wookmark plugin + lightbox */ function l($pin) { $d = array("width" => 0, "height" => 0); $filepath = __DIR__ . '/pins/mini-' . $pin['pin_image_name']; if (file_exists($filepath)) { $image = new Imagick($filepath); $d = $image->getImageGeometry(); } $link = '<a href="pins/' . $pin['pin_image_name'] . '" rel="lightbox">'; $link .= '<img src="pins/mini-' . $pin['pin_image_name'] . '" alt="' . $pin['description'] . ' - ' . $pin['board'] . '" width="' . $d['width'] . '" height="' . $d['height'] . '">'; $link .= '</a>'; $link .= '<p class="info">' . $pin['description'] . '</p><p class="board">::' . $pin['board'] . '</p>'; return $link; }
function generateQRCode($hash) { $link = Config::HOST . Config::BASE_URI . 'gallery/' . $hash; $imageBlob = (new Endroid\QrCode\QrCode())->setText($link)->setPadding(7)->setErrorCorrection('high')->get(); $qrcode = new Imagick(); $qrcode->readImageBlob($imageBlob); $qrcode->scaleImage(600, 600, true); $camera = new Imagick(__DIR__ . '/camera.png'); $qrcodeSize = $qrcode->getImageGeometry(); $cameraSize = $camera->getImageGeometry(); $qrcode->compositeImage($camera, Imagick::COMPOSITE_DEFAULT, round(($qrcodeSize['width'] - $cameraSize['width']) / 2), round(($qrcodeSize['height'] - $cameraSize['height']) / 2)); $qrcode->setImageFormat('png'); header('Content-Type: image/png'); echo $qrcode->getImageBlob(); $qrcode->clear(); $qrcode->destroy(); $camera->clear(); $camera->destroy(); exit; }
/** * Rotates the current image * * @param float $angle Rotation angle in degree * @param array $options Supported options: * <ul> * <li>'canvasColor' : array(r ,g, b), named color or #rrggbb</li> * </ul> * * @return bool|PEAR_Error TRUE or a PEAR_Error object on error * @access public */ function rotate($angle, $options = null) { if ($angle % 360 == 0) { return true; } $color = $this->_getColor('canvasColor', $options, array(255, 255, 255)); if (is_array($color)) { $color = $this->colorarray2colorhex($color); } $pixel = new ImagickPixel($color); try { $this->imagick->rotateImage($pixel, $angle); } catch (ImagickException $e) { return $this->raiseError('Cannot create a new imagick image for the rotation: ' . $e->getMessage(), IMAGE_TRANSFORM_ERROR_FAILED); } $info = $this->imagick->getImageGeometry(); $this->new_x = $info['width']; $this->new_y = $info['height']; return true; }
/** * Prepare the image for output, scaling and flattening as required * * @since 2.10 * @uses self::$image updates the image in this Imagick object * * @param integer zero or new width * @param integer zero or new height * @param boolean proportional fit (true) or exact fit (false) * @param string output MIME type * @param integer compression quality; 1 - 100 * * @return void */ private static function _prepare_image($width, $height, $best_fit, $type, $quality) { if (is_callable(array(self::$image, 'scaleImage'))) { if (0 < $width && 0 < $height) { // Both are set; use them as-is self::$image->scaleImage($width, $height, $best_fit); } elseif (0 < $width || 0 < $height) { // One is set; scale the other one proportionally if reducing $image_size = self::$image->getImageGeometry(); if ($width && isset($image_size['width']) && $width < $image_size['width']) { self::$image->scaleImage($width, 0); } elseif ($height && isset($image_size['height']) && $height < $image_size['height']) { self::$image->scaleImage(0, $height); } } else { // Neither is specified, apply defaults self::$image->scaleImage(150, 0); } } if (0 < $quality && 101 > $quality) { if ('image/jpeg' == $type) { self::$image->setImageCompressionQuality($quality); self::$image->setImageCompression(imagick::COMPRESSION_JPEG); } else { self::$image->setImageCompressionQuality($quality); } } if ('image/jpeg' == $type) { if (is_callable(array(self::$image, 'setImageBackgroundColor'))) { self::$image->setImageBackgroundColor('white'); } if (is_callable(array(self::$image, 'mergeImageLayers'))) { self::$image = self::$image->mergeImageLayers(imagick::LAYERMETHOD_FLATTEN); } elseif (is_callable(array(self::$image, 'flattenImages'))) { self::$image = self::$image->flattenImages(); } } }
function is_allowed_filetype() { if (count($this->allowed_types) == 0 or !is_array($this->allowed_types)) { $this->set_error('upload_no_file_types'); return FALSE; } $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe', 'eps'); foreach ($this->allowed_types as $val) { $mime = $this->mimes_types(strtolower($val)); // Images get some additional checks if (in_array(strtolower($val), $image_types)) { if (strtolower($val) === 'eps') { try { $img = new Imagick($this->file_temp); $geo = $img->getImageGeometry(); } catch (ImagickException $e) { return false; } } else { if (getimagesize($this->file_temp) === false) { return false; } } } if (is_array($mime)) { if (in_array($this->file_type, $mime, true)) { return true; } } else { if ($mime == $this->file_type) { return true; } } } return false; }
protected function getImage($image, &$width, &$height) { if (is_object($image) && $image instanceof image_imagick) { try { $image->image->setImageCompressionQuality(100); } catch (Exception $e) { return false; } $width = $image->width; $height = $image->height; return $image->image; } elseif (is_object($image) && $image instanceof Imagick) { try { $image->setImageCompressionQuality(100); $size = $image->getImageGeometry(); } catch (Exception $e) { return false; } $width = $size['width']; $height = $size['height']; return $image; } elseif (is_string($image)) { try { $image = new Imagick($image); $image->setImageCompressionQuality(100); $size = $image->getImageGeometry(); } catch (Exception $e) { return false; } $width = $size['width']; $height = $size['height']; return $image; } else { return false; } }
/** * Add watermark to image * @param string $watermarkPath Path to watermark image * @param string $xPos Horizontal position - 'left', 'right' or 'center' * @param string $yPos Vertical position - 'top', 'bottom' or 'center' * @param bool|int|string $xSize Horizontal watermark size: 100, '50%', 'auto' etc. * @param bool|int|string $ySize Vertical watermark size: 100, '50%', 'auto' etc. * @param bool $xOffset * @param bool $yOffset * @return Imagick * @throws Exception */ public function watermark($watermarkPath, $xPos, $yPos, $xSize = false, $ySize = false, $xOffset = false, $yOffset = false) { $watermark = new \Imagick($watermarkPath); // resize watermark $newSizeX = false; $newSizeY = false; if ($xSize !== false) { if (is_numeric($xSize)) { $newSizeX = $xSize; } elseif (is_string($xSize) && substr($xSize, -1) === '%') { $float = str_replace('%', '', $xSize) / 100; $newSizeX = $this->width * (double) $float; } } if ($ySize !== false) { if (is_numeric($ySize)) { $newSizeY = $ySize; } elseif (is_string($ySize) && substr($ySize, -1) === '%') { $float = str_replace('%', '', $ySize) / 100; $newSizeY = $this->height * (double) $float; } } if ($newSizeX !== false && $newSizeY !== false) { $watermark->adaptiveResizeImage($newSizeX, $newSizeY); } elseif ($newSizeX !== false && $newSizeY === false) { $watermark->adaptiveResizeImage($newSizeX, 0); } elseif ($newSizeX === false && $newSizeY !== false) { $watermark->adaptiveResizeImage(0, $newSizeY); } $startX = false; $startY = false; $watermarkSize = $watermark->getImageGeometry(); if ($yPos === 'top') { $startY = 0; if ($yOffset !== false) { $startY += $yOffset; } } elseif ($yPos === 'bottom') { $startY = $this->height - $watermarkSize['height']; if ($yOffset !== false) { $startY -= $yOffset; } } elseif ($yPos === 'center') { $startY = $this->height / 2 - $watermarkSize['height'] / 2; } else { throw new \Exception('Param $yPos should be "top", "bottom" or "center" insteed "' . $yPos . '"'); } if ($xPos === 'left') { $startX = 0; if ($xOffset !== false) { $startX += $xOffset; } } elseif ($xPos === 'right') { $startX = $this->width - $watermarkSize['width']; if ($xOffset !== false) { $startX -= $xOffset; } } elseif ($xPos === 'center') { $startX = $this->width / 2 - $watermarkSize['width'] / 2; } else { throw new \Exception('Param $xPos should be "left", "right" or "center" insteed "' . $xPos . '"'); } $this->image->compositeImage($watermark, \Imagick::COMPOSITE_OVER, $startX, $startY); return $this; }
/** * upload comment data */ public function upload() { $data = (array) json_decode($this->request->data); try { if (!isset($_FILES['uploadFile'])) { throw new Exception(__("Chyba neexistujúci súbor"), 500); } // filename and path $filename = Security::hash($_FILES['uploadFile']['name']); $extenstion = strtolower(pathinfo($_FILES['uploadFile']['name'], PATHINFO_EXTENSION)); $full_image_name = $filename . "." . $extenstion; $upload_paths = Configure::read('upload_paths'); $file_path = $upload_paths['comments'] . '/' . $full_image_name; // UPLOAD FILE if (!move_uploaded_file($_FILES['uploadFile']['tmp_name'], $file_path)) { throw new Exception(__("Chyba súbor nebol nahraty"), 500); } // image resize $thumb = new Imagick($file_path); $imageprops = $thumb->getImageGeometry(); if ($imageprops['width'] >= 400) { $thumb->resizeImage(500, 400, Imagick::FILTER_LANCZOS, 1, true); $thumb->writeImage($file_path); } // Save image into DB $save_data = array('comment_id' => $data['data']->Comment->id, 'name' => $full_image_name); $this->Image->save($save_data); $data['files'] = $_FILES; } catch (Exception $ex) { throw new Exception($ex->getMessage(), $ex->getCode()); } $this->set($data); $this->set('_serialize', array_keys($data)); }
/** * Compares to images by given file path * * @param $image1 Path to the exprected reference image * @param $image2 Path to the current image in the screenshot * @return array Result of the comparison */ private function compareImages($image1, $image2) { $this->debug("Trying to compare {$image1} with {$image2}"); $imagick1 = new \Imagick($image1); $imagick2 = new \Imagick($image2); $imagick1Size = $imagick1->getImageGeometry(); $imagick2Size = $imagick2->getImageGeometry(); $maxWidth = max($imagick1Size['width'], $imagick2Size['width']); $maxHeight = max($imagick1Size['height'], $imagick2Size['height']); $imagick1->extentImage($maxWidth, $maxHeight, 0, 0); $imagick2->extentImage($maxWidth, $maxHeight, 0, 0); try { $result = $imagick1->compareImages($imagick2, \Imagick::METRIC_MEANSQUAREERROR); $result[0]->setImageFormat('png'); $result['currentImage'] = clone $imagick2; $result['currentImage']->setImageFormat('png'); } catch (\ImagickException $e) { $this->debug("IMagickException! could not campare image1 ({$image1}) and image2 ({$image2}).\nExceptionMessage: " . $e->getMessage()); $this->fail($e->getMessage() . ", image1 {$image1} and image2 {$image2}."); } return $result; }
public function doWatermarkImage($filepath, $mime = 'image/png') { $path_watermark = osc_content_path() . 'uploads/watermark.png'; if (osc_use_imagick()) { $im = new Imagick($filepath); $wm = new Imagick($path_watermark); $geo = $im->getImageGeometry(); $wgeo = $wm->getImageGeometry(); switch (osc_watermark_place()) { case 'tl': $dest_x = 0; $dest_y = 0; break; case 'tr': $dest_x = $geo['width'] - $wgeo['width']; $dest_y = 0; break; case 'bl': $dest_x = 0; $dest_y = $geo['height'] - $wgeo['height']; break; case 'br': $dest_x = $geo['width'] - $wgeo['width']; $dest_y = $geo['height'] - $wgeo['height']; break; default: $dest_x = $geo['width'] / 2 - $wgeo['width'] / 2; $dest_y = $geo['height'] / 2 - $wgeo['height'] / 2; break; } $im->compositeImage($wm, imagick::COMPOSITE_OVER, $dest_x, $dest_y); $this->saveImageFile($im, 'image/jpeg', $filepath); $im->destroy(); $wm->destroy(); } else { $watermark = imagecreatefrompng($path_watermark); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = $this->getImageResource($filepath, $mime); $size = getimagesize($filepath); switch (osc_watermark_place()) { case 'tl': $dest_x = 0; $dest_y = 0; break; case 'tr': $dest_x = $size[0] - $watermark_width; $dest_y = 0; break; case 'bl': $dest_x = 0; $dest_y = $size[1] - $watermark_height; break; case 'br': $dest_x = $size[0] - $watermark_width; $dest_y = $size[1] - $watermark_height; break; default: $dest_x = $size[0] / 2 - $watermark_width / 2; $dest_y = $size[1] / 2 - $watermark_height / 2; break; } $this->imagecopymerge_alpha($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); $this->saveImageFile($image, 'image/jpeg', $filepath); imagedestroy($image); imagedestroy($watermark); } }
/** * Sets or updates current image size. * * @since 3.5.0 * @access protected * * @param int $width * @param int $height * * @return true|WP_Error */ protected function update_size($width = null, $height = null) { $size = null; if (!$width || !$height) { try { $size = $this->image->getImageGeometry(); } catch (Exception $e) { return new WP_Error('invalid_image', __('Could not read image size'), $this->file); } } if (!$width) { $width = $size['width']; } if (!$height) { $height = $size['height']; } return parent::update_size($width, $height); }
function thumbnailImage($imagePath) { $im = new Imagick(); $im->setBackgroundColor(new ImagickPixel('transparent')); $im->readImage(realpath($imagePath)); $dim = $im->getImageGeometry(); if (!isset($_GET['wh'])) { $wh = 100; } $wh = intval($_GET['wh']); if ($wh <= 0) { $wh = 100; } // $aspect=floatval($dim['width'])/floatval($dim['height']); // $inverse_aspect=floatval($dim['height'])/floatval($dim['width']); $width = $wh; $height = $wh; $im->setImageFormat("png32"); $im->thumbnailImage($width, $height, true, true); header("Content-Type: image/png"); echo $im; }
public function prePersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); $container = $this->container; if (!$entity instanceof Post) { return; } $rootDir = $this->container->get('kernel')->getRootDir(); $uploadsDirectory = $container->getParameter('ziiweb_blog.uploads_directory'); $paths = array(); foreach ($entity->getPaths() as $path) { $imagick = new \Imagick($path->getRealPath()); //generate unique filename $filename = sha1(uniqid(mt_rand(), true)); $paths[] = $filenameWithExtension = $filename . '.' . $path->guessExtension(); $size = $imagick->getImageGeometry(); $anchoGenerada = $size['width'] * 550 / $size['height']; $imagick->resizeImage($anchoGenerada, 550, false, 1); $imagick->writeImage($rootDir . '/' . $uploadsDirectory . '/' . $filenameWithExtension); } $entity->setPaths($paths); }