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; }
/** * Generates a new jpg image with new sizes from an already existing file. * (This will also work on raw files, but it will be exceptionally * slower than extracting the preview). * * @param string $sourceFilePath the path to the original file * @param string $targetFilePath the path to the target file * @param int $width the max width * @param int $height the max height of the image * @param int $quality the quality of the new image (0-100) * * @throws \InvalidArgumentException * * @return void. */ public static function generateImage($sourceFilePath, $targetFilePath, $width, $height, $quality = 60) { if (!self::checkFile($sourceFilePath)) { throw new \InvalidArgumentException('Incorrect filepath given'); } $im = new \Imagick($sourceFilePath); $im->setImageFormat('jpg'); $im->setImageCompressionQuality($quality); $im->stripImage(); $im->thumbnailImage($width, $height, true); $im->writeImage($targetFilePath); $im->clear(); $im->destroy(); }
/** * 保存图像 * @param string $imgname 图像保存名称 * @param string $type 图像类型 * @param boolean $interlace 是否对JPEG类型图像设置隔行扫描 * @throws \Exception */ public function save($imgname, $type = NULL, $interlace = true) { if (empty($this->img)) { throw new \Exception(_('No image resources can be saved')); } //设置图片类型 if (is_null($type)) { $type = $this->info['type']; } else { $type = strtolower($type); $this->img->setImageFormat($type); } //JPEG图像设置隔行扫描 if ('jpeg' == $type || 'jpg' == $type) { $this->img->setImageInterlaceScheme(1); } //去除图像配置信息 $this->img->stripImage(); //保存图像 $imgname = realpath(dirname($imgname)) . '/' . basename($imgname); //强制绝对路径 if ('gif' == $type) { $this->img->writeImages($imgname, true); } else { $this->img->writeImage($imgname); } }
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; }
function upload_image($arr_image, $location, $compression = null, $width = 245, $height = 170) { $image_location = ""; $allowedExts = array("gif", "jpeg", "jpg", "png", "JPG", "JPEG", "GIF", "PNG", "pdf", "PDF"); $temp = explode(".", $arr_image["file"]["name"]); $extension = end($temp); if (($arr_image["file"]["type"] == "image/gif" || $arr_image["file"]["type"] == "image/jpeg" || $arr_image["file"]["type"] == "image/jpg" || $arr_image["file"]["type"] == "image/pjpeg" || $arr_image["file"]["type"] == "image/x-png" || $arr_image["file"]["type"] == "image/png") && $arr_image["file"]["size"] < 1024 * 1000 * 10 && in_array($extension, $allowedExts)) { if ($arr_image["file"]["error"] > 0) { echo "Return Code: " . $arr_image["file"]["error"] . "<br>"; } else { $compression_type = Imagick::COMPRESSION_JPEG; $image_location = $location . "." . $extension; if (move_uploaded_file($arr_image["file"]["tmp_name"], $image_location)) { //echo "Image Uploaded to : ".$image_location; } else { //echo "Image not uploaded"; } if (is_null($compression)) { $im = new Imagick($image_location); $im->setImageFormat('jpg'); $im->setImageCompression($compression_type); $im->setImageCompressionQuality(95); $im->stripImage(); $im->thumbnailImage($width, $height); $image_location = $location . ".jpg"; $im->writeImage($image_location); } } } return $image_location; }
/** * 入力された画像がExifであればエラーを記録し、JFIFに変換します。 * @param \Imagick $imagick JFIFかExif。 */ protected function convertExifToJFIF(\Imagick $imagick) { if ($imagick->getImageProperties('exif:*')) { $this->logger->error(sprintf(_('「%s」はExif形式です。'), $this->filename)); switch ($imagick->getImageOrientation()) { case \Imagick::ORIENTATION_TOPRIGHT: $imagick->flopImage(); break; case \Imagick::ORIENTATION_BOTTOMRIGHT: $imagick->rotateImage('none', 180); break; case \Imagick::ORIENTATION_BOTTOMLEFT: $imagick->rotateImage('none', 180); $imagick->flopImage(); break; case \Imagick::ORIENTATION_LEFTTOP: $imagick->rotateImage('none', 90); $imagick->flopImage(); break; case \Imagick::ORIENTATION_RIGHTTOP: $imagick->rotateImage('none', 90); break; case \Imagick::ORIENTATION_RIGHTBOTTOM: $imagick->rotateImage('none', 270); $imagick->flopImage(); break; case \Imagick::ORIENTATION_LEFTBOTTOM: $imagick->rotateImage('none', 270); break; } $imagick->stripImage(); } }
/** * Outputs the image. * * @see XenForo_Image_Abstract::output() */ public function output($outputType, $outputFile = null, $quality = 85) { $this->_image->stripImage(); // NULL means output directly switch ($outputType) { case IMAGETYPE_GIF: if (is_callable(array($this->_image, 'optimizeimagelayers'))) { $this->_image->optimizeimagelayers(); } $success = $this->_image->setImageFormat('gif'); break; case IMAGETYPE_JPEG: $success = $this->_image->setImageFormat('jpeg') && $this->_image->setImageCompression(Imagick::COMPRESSION_JPEG) && $this->_image->setImageCompressionQuality($quality); break; case IMAGETYPE_PNG: $success = $this->_image->setImageFormat('png'); break; default: throw new XenForo_Exception('Invalid output type given. Expects IMAGETYPE_XXX constant.'); } try { if ($success) { if (!$outputFile) { echo $this->_image->getImagesBlob(); } else { $success = $this->_image->writeImages($outputFile, true); } } } catch (ImagickException $e) { return false; } return $success; }
public static function get($username) { $lowercase = strtolower($username); $skin = './minecraft/skins/' . $lowercase . '.png'; if (file_exists($skin)) { if (time() - filemtime($skin) < self::$expires) { return $lowercase; } $cached = true; } $binary = self::fetch('http://s3.amazonaws.com/MinecraftSkins/' . $username . '.png'); if ($binary === false) { if ($cached) { return $lowercase; } header('Status: 404 Not Found'); return $username == self::DEFAULT_SKIN ? $lowercase : self::get(self::DEFAULT_SKIN); } $img = new Imagick(); $img->readImageBlob($binary); $img->stripImage(); // strip metadata $img->writeImage($skin); self::_getHelm($img)->writeImage('./minecraft/helms/' . $lowercase . '.png'); self::_getHead($img)->writeImage('./minecraft/heads/' . $lowercase . '.png'); self::_getPlayer($img)->writeImage('./minecraft/players/' . $lowercase . '.png'); return $lowercase; }
/** * Do some tricks to cleanup and minimize the thumbnails size * * @param Imagick $image */ protected function enhance(\Imagick $image) { $image->setImageCompression(\Imagick::COMPRESSION_JPEG); $image->setImageCompressionQuality(75); $image->contrastImage(1); $image->adaptiveBlurImage(1, 1); $image->stripImage(); }
/** * Remove excess metadata. * * @throws ProcessorException * * @return $this */ public function removeMeta() { try { $this->im->stripImage(); } catch (\Exception $e) { throw new ProcessorException('Could not remove image metadata: %s', null, $e, (string) $e->getMessage()); } return $this; }
/** * Returns the raw data for this image. * * @param boolean $convert Ignored for imagick driver. * * @return string The raw image data. */ public function raw($convert = false) { try { $this->_imagick->stripImage(); return $this->_imagick->getImageBlob(); } catch (ImagickException $e) { throw new Horde_Image_Exception($e); } }
/** * {@inheritdoc} */ public function strip() { try { $this->imagick->stripImage(); } catch (\ImagickException $e) { throw new RuntimeException('Strip operation failed', $e->getCode(), $e); } return $this; }
/** * 处理图片,不改变分辨率,减少图片文件大小 * @param [string] $src 原图路径 * @param [int] [图片质量] * @param [string] $dest 目标图路径 * @return [void] */ public function tinyJpeg($src, $quality = 60, $dest) { $img = new Imagick(); $img->readImage($src); $img->setImageCompression(Imagick::COMPRESSION_JPEG); $img->setImageCompressionQuality($quality); $img->stripImage(); $img->writeImage($dest); $img->clear(); }
function render() { //Example Imagick::stripImage $imagick = new \Imagick(realpath("../imagick/images/Biter_500.jpg")); $bytes = $imagick->getImageBlob(); echo "Image byte size before stripping: " . strlen($bytes) . "<br/>"; $imagick->stripImage(); $bytes = $imagick->getImageBlob(); echo "Image byte size after stripping: " . strlen($bytes) . "<br/>"; //Example end }
/** * {@inheritdoc} * * @return ImageInterface */ public function strip() { try { try { $this->profile($this->palette->profile()); } catch (\Exception $e) { // here we discard setting the profile as the previous incorporated profile // is corrupted, let's now strip the image } $this->imagick->stripImage(); } catch (\ImagickException $e) { throw new RuntimeException('Strip operation failed', $e->getCode(), $e); } return $this; }
protected function _save($file, $quality) { $extension = pathinfo($file, PATHINFO_EXTENSION); $type = $this->_save_function($extension, $quality); $this->im->setImageCompressionQuality($quality); $this->im->stripImage(); if ($this->im->getNumberImages() > 1 && $extension == "gif") { $res = $this->im->writeImages($file, true); } else { $res = $this->im->writeImage($file); } if ($res) { $this->type = $type; $this->mime = image_type_to_mime_type($type); return true; } return false; }
/** * * Creates a thumb for the given path * * @param $path * @param $postId * @return bool * @author Tim Perry * */ protected function createPdfThumb($path, $postId) { if (has_post_thumbnail($postId)) { return false; } if (!class_exists("Imagick")) { return false; } $pathInfo = pathinfo($path); $outputPath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . ".png"; if (file_exists($outputPath)) { return false; } $im = new \Imagick($path . '[0]'); $im->setImageFormat('png'); $im->stripImage(); $im->writeImage($outputPath); return $outputPath; }
public function image($request_name, $extensions, $size, $throw = false) { $file_source = isset($_FILES[$request_name]) ? $_FILES[$request_name] : null; if ($file_source == null) { return false; } list($width, $height, $type) = getimagesize($file_source['tmp_name']); if (isset($type) && !in_array($type, self::$image_types)) { return false; } $ext = explode(".", $file_source["name"]); $file_extension = strtolower(end($ext)); if (in_array($file_extension, $extensions) == false) { return false; } if ($file_source['size'] > $size * 1024 * 1024) { return false; } $file_name = $this->getRandomName(); $destination = self::UPLOADS_DIRECTORY . '/' . $file_name . '.' . $file_extension; move_uploaded_file($file_source['tmp_name'], $destination); if ($_GET['channel'] == self::CHANNEL_APP) { $compression_type = Imagick::COMPRESSION_JPEG; $thumbnail = new Imagick($destination); $thumbnail->setImageCompression($compression_type); $thumbnail->setImageCompressionQuality(75); $thumbnail->stripImage(); $image_width = $thumbnail->getImageWidth(); $width = min($image_width, 800); $thumbnail->thumbnailImage($width, null); App_Controller_Site_Images::delete($destination); $thumbnail->writeImage($destination); } $time = date('Y-m-d H:i:s'); $ip = $_SERVER['REMOTE_ADDR']; $channel = self::CHANNEL_WEB; if (isset($_GET['channel']) && ($_GET['channel'] == self::CHANNEL_APP || $_GET['channel'] == self::CHANNEL_WEB)) { $channel = $_GET['channel']; } $query = "INSERT INTO `uploads` (`src`,`upload_time`,`token`,`ip`,`channel`) VALUES ('{$destination}','{$time}','{$file_name}','{$ip}','{$channel}')"; App_Db::getInstance()->getConn()->query($query); return $file_name; }
function createThumbnail($filename, $thname, $width = 100, $height = 100, $cdn = null) { $filePath = 'pdfslice'; try { $extension = substr($filename, strrpos($filename, '.') + 1 - strlen($filename)); $fallback_save_path = $filePath; if ($extension == "svg") { $im = new Imagick(); $svgdata = file_get_contents($filename); $svgdata = svgScaleHack($svgdata, $width, $height); //$im->setBackgroundColor(new ImagickPixel('transparent')); $im->readImageBlob($svgdata); $im->setImageFormat("jpg"); $im->resizeImage($width, $height, imagick::FILTER_LANCZOS, 1); $raw_data = $im->getImageBlob(); is_null($cdn) ? file_put_contents($fallback_save_path . '/' . $thname, $im->getImageBlob()) : ''; } else { if ($extension == "jpg") { $im = new Imagick($filename); $im->stripImage(); // Save as progressive JPEG $im->setInterlaceScheme(Imagick::INTERLACE_PLANE); $raw_data = $im->resizeImage($width, $height, imagick::FILTER_LANCZOS, 1); // Set quality // $im->setImageCompressionQuality(85); is_null($cdn) ? $im->writeImage($fallback_save_path . '/' . $thname) : ''; } } if (!is_null($cdn)) { $imageObject = $cdn->DataObject(); $imageObject->SetData($raw_data); $imageObject->name = $thname; $imageObject->content_type = 'image/jpg'; $imageObject->Create(); } $im->clear(); $im->destroy(); return true; } catch (Exception $e) { return false; } }
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; } }
static function fixImageRotationOld($file) { $degrees = NULL; $image = imagecreatefromstring(file_get_contents($file)); try { $exif = exif_read_data($file); } catch (Exception $exp) { return; } if ($exif) { $exif = \exif_read_data($file, 'ANY_TAG'); if (isset($exif['Orientation'])) { switch ($exif['Orientation']) { case 3: $degrees = 180; break; case 6: $degrees = 90; break; case 8: $degrees = -90; break; } } if (class_exists("\\Imagick")) { try { $img = new \Imagick($file); $img->stripImage(); if ($degrees) { $img->rotateimage("#ffffff", $degrees); } $img->writeImage($file); $img->clear(); $img->destroy(); } catch (Exception $e) { } } return; } }
private function make_thumbnail_Imagick($src_path, $width, $height, $dest) { $image = new Imagick($src_path); # Select the first frame to handle animated images properly if (is_callable(array($image, 'setIteratorIndex'))) { $image->setIteratorIndex(0); } // устанавливаем качество $format = $image->getImageFormat(); if ($format == 'JPEG' || $format == 'JPG') { $image->setImageCompression(Imagick::COMPRESSION_JPEG); } $image->setImageCompressionQuality(85); $h = $image->getImageHeight(); $w = $image->getImageWidth(); // если не указана одна из сторон задаем ей пропорциональное значение if (!$width) { $width = round($w * ($height / $h)); } if (!$height) { $height = round($h * ($width / $w)); } list($dx, $dy, $wsrc, $hsrc) = $this->crop_coordinates($height, $h, $width, $w); // обрезаем оригинал $image->cropImage($wsrc, $hsrc, $dx, $dy); $image->setImagePage($wsrc, $hsrc, 0, 0); // Strip out unneeded meta data $image->stripImage(); // уменьшаем под размер $image->scaleImage($width, $height); $image->writeImage($dest); chmod($dest, 0755); $image->clear(); $image->destroy(); return true; }
/** * Remove exif data from an image by rewriting it * @param $image * @return bool */ public static function removeExifData($image) { if (extension_loaded('imagick')) { try { $img = new Imagick($image); $img->stripImage(); $img->writeImage($image); $img->clear(); $img->destroy(); } catch (Exception $e) { } } else { if (extension_loaded('gd')) { try { $info = @getimagesize($image); if (!empty($info[2]) && $info[2] === IMAGETYPE_JPEG) { $handle = imagecreatefromjpeg($image); imagejpeg($handle, $image, 100); @imagedestroy($handle); } } catch (Exception $e) { } } } return true; }
/** * Strips EXIF data from image * * @return Imagick */ public function strip() { $this->image->stripImage(); $this->operations[] = 'strip'; return $this; }
/** * Convert image to a given type * * @param int $type Destination file type (see class constants) * @param string $filename Output filename (if empty, original file will be used * and filename extension will be modified) * * @return bool True on success, False on failure */ public function convert($type, $filename = null) { $rcube = rcube::get_instance(); $convert = $rcube->config->get('im_convert_path', false); if (!$filename) { $filename = $this->image_file; // modify extension if ($extension = self::$extensions[$type]) { $filename = preg_replace('/\\.[^.]+$/', '', $filename) . '.' . $extension; } } // use ImageMagick in command line if ($convert) { $p['in'] = $this->image_file; $p['out'] = $filename; $p['type'] = self::$extensions[$type]; $result = rcube::exec($convert . ' 2>&1 -colorspace sRGB -strip -quality 75 {in} {type}:{out}', $p); if ($result === '') { chmod($filename, 0600); return true; } } // use PHP's Imagick class if (class_exists('Imagick', false)) { try { $image = new Imagick($this->image_file); $image->setImageColorspace(Imagick::COLORSPACE_SRGB); $image->setImageCompressionQuality(75); $image->setImageFormat(self::$extensions[$type]); $image->stripImage(); if ($image->writeImage($filename)) { @chmod($filename, 0600); return true; } } catch (Exception $e) { rcube::raise_error($e, true, false); } } // use GD extension (TIFF isn't supported) $props = $this->props(); // do we have enough memory? (#1489937) if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && !$this->mem_check($props)) { return false; } if ($props['gd_type']) { if ($props['gd_type'] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) { $image = imagecreatefromjpeg($this->image_file); } else { if ($props['gd_type'] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) { $image = imagecreatefromgif($this->image_file); } else { if ($props['gd_type'] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')) { $image = imagecreatefrompng($this->image_file); } else { // @TODO: print error to the log? return false; } } } if ($type == self::TYPE_JPG) { $result = imagejpeg($image, $filename, 75); } else { if ($type == self::TYPE_GIF) { $result = imagegif($image, $filename); } else { if ($type == self::TYPE_PNG) { $result = imagepng($image, $filename, 6, PNG_ALL_FILTERS); } } } if ($result) { @chmod($filename, 0600); return true; } } // @TODO: print error to the log? return false; }
$pagina_actual = 1; while ($f = mysql_fetch_assoc($r)) { $ref = $general->addChild('ref'); //$ref->addAttribute("titulo",iconv('ISO-8859-1','UTF-8//TRANSLIT',$f['titulo'])); $ref->addAttribute("titulo", $f['titulo']); $ref->addAttribute("pagina", $pagina_actual); $cp = 'SELECT foto, pc.titulo FROM flores_productos_categoria LEFT JOIN flores_producto_contenedor AS pc USING(codigo_producto) LEFT JOIN flores_producto_variedad USING(codigo_producto) WHERE codigo_categoria=' . $f['codigo_categoria'] . ' GROUP BY codigo_producto'; $rp = db_consultar($cp); $pagina_actual += 1 + mysql_numrows($rp); while ($fp = mysql_fetch_assoc($rp)) { if (!file_exists('catalogo360/pages/' . $fp['foto'])) { $im = new Imagick('IMG/i/' . $fp['foto']); $im->setCompression(Imagick::COMPRESSION_JPEG); $im->setCompressionQuality(90); $im->setImageFormat('jpeg'); $im->stripImage(); $draw = new ImagickDraw(); $pixel = new ImagickPixel('gray'); $pixel->setColor('black'); $draw->setFont('flower.ttf'); $draw->setFontSize(30); $im->thumbnailImage(350, 525, false); $im->annotateImage($draw, 10, 45, 0, $fp['titulo']); $im->writeImage('catalogo360/pages/' . $fp['foto']); $im->clear(); $im->destroy(); unset($im); } $XMLP->pages->addChild('page', 'pages/' . $fp['foto']); } }
/** * @static 使用ImageMagick压缩图片 * @param string $srcPath 图片地址 * @return bool */ public static function compress($srcPath = '', $quality = 80) { if (!extension_loaded('imagick') || empty($srcPath)) { return false; } try { $imagick = new Imagick(); if (empty($imagick)) { echo 1; } if (!$imagick->readImage($srcPath)) { echo 2; } if (!$imagick->setImageCompression(Imagick::COMPRESSION_JPEG)) { echo 4; } if (!$imagick->setImageCompressionQuality($quality)) { echo 5; } if (!$imagick->stripImage()) { echo 3; } if (!$imagick->writeImage()) { echo 6; } if (!$imagick->clear()) { echo 7; } if (!$imagick->destroy()) { echo 8; } return true; } catch (Exception $e) { echo $e->getMessage(); return false; } }
public function actionGo() { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br>"; } else { $f = $_POST['filter']; $capPhoto = $_POST['capPhoto']; $min_rand = rand(0, 1000); $max_rand = rand(100000000000, 10000000000000000); $name_file = rand($min_rand, $max_rand); //this part is for creating random name for image $ext = end(explode(".", $_FILES["file"]["name"])); //gets extension $file = Yii::app()->request->baseUrl . "photo/" . $name_file . "." . $ext; move_uploaded_file($_FILES["file"]["tmp_name"], Yii::app()->request->baseUrl . "photo/" . $name_file . "." . $ext); chmod($file, 0777); if (exif_imagetype($file) == IMAGETYPE_JPEG) { $exif = exif_read_data($file); if (isset($exif['Orientation'])) { $orientation = $exif['Orientation']; if ($orientation == 6) { $imz = new Imagick($file); $imz->rotateimage("#FFF", 90); $imz->writeImage($file); chmod($file, 0777); } else { if ($orientation == 8) { $imz = new Imagick($file); $imz->rotateimage("#FFF", -90); $imz->writeImage($file); chmod($file, 0777); } } } } // Max vert or horiz resolution $maxsize = 1200; // create new Imagick object $image = new Imagick($file); // 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(); // Writes resultant image to output directory $image->writeImage($file); // Destroys Imagick object, freeing allocated resources in the process $image->destroy(); chmod($file, 0777); $filter = Instagraph::factory($file, $file); $filter->{$f}(); // 320 Show Preview $immid = new Imagick($file); if ($immid->getimagewidth() > 320) { $immid->thumbnailImage(320, null); $immid->writeImage(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext); $immid->destroy(); chmod(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext, 0777); } else { $immid->writeImage(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext); $immid->destroy(); chmod(Yii::app()->request->baseUrl . "thumb/thumb320_" . $name_file . "." . $ext, 0777); } // null x 230 show last upload $imlast = new Imagick($file); $imlast->thumbnailimage(null, 230); $imlast->writeImage(Yii::app()->request->baseUrl . "thumb/thumb230_" . $name_file . "." . $ext); $imlast->destroy(); chmod(Yii::app()->request->baseUrl . "thumb/thumb230_" . $name_file . "." . $ext, 0777); // 130 x 110 thumbmail $im = new Imagick($file); $im->thumbnailImage(130, 110); $im->writeImage(Yii::app()->request->baseUrl . "thumb/thumb_" . $name_file . "." . $ext); chmod(Yii::app()->request->baseUrl . "thumb/thumb_" . $name_file . "." . $ext, 0777); $im->destroy(); $photo = new Photo(); $photo->link = $file; $photo->fbid = Yii::app()->facebook->getUser(); $photo->ip = $_SERVER['REMOTE_ADDR']; if ($photo->save()) { $id = $photo->id; if (isset($_POST['shareFB'])) { $share = 1; } else { $share = 0; } if ($share == 1) { $cr = "\n" . "http://www.pla2gram.com/?p=" . $id . "&theater=1"; $capFB = $capPhoto . $cr; // Post to Facebook $args = array('message' => $capFB); $args['image'] = '@' . realpath($file); Yii::app()->facebook->api('/me/photos', 'post', $args); Helper::redir("/?p=" . $id, 0); } else { Helper::redir("/?p=" . $id, 0); } } else { print_r($photo->getErrors()); } } }
/** * @ORM\PostPersist() * @ORM\PostUpdate() */ public function postPersist() { $destination = $this->getAbsoluteFileName(); if (!is_writable(dirname($destination))) { echo "justo antes del mkdir {$destination}"; if (!mkdir(dirname($destination), 0755, true)) { throw new Exception("Cannot create '" . dirname($destination) . "' folder."); } } $image = new \Imagick($this->imagePath); $image->stripImage(); $image->setImageFormat("jpg"); $image->writeImage($destination); unset($image); }
/** * Remove exif data from an image by rewriting it * @param $image * @return bool */ public static function removeExifData($image) { if (extension_loaded('imagick')) { try { $img = new Imagick($image); $img->stripImage(); $img->writeImage($image); $img->clear(); $img->destroy(); return true; } catch (Exception $e) { } } else { if (extension_loaded('gd')) { try { $info = @getimagesize($image); if (!empty($info)) { if ($info[2] === IMAGETYPE_JPEG) { $handle = imagecreatefromjpeg($image); if (is_resource($handle)) { imagejpeg($handle, $image, 100); @imagedestroy($handle); return true; } } if ($info[2] === IMAGETYPE_PNG) { $handle = imagecreatefrompng($image); if (is_resource($handle)) { // Allow transparency for the new image handle. imagealphablending($handle, false); imagesavealpha($handle, true); imagepng($handle, $image, 0); @imagedestroy($handle); return true; } } } } catch (Exception $e) { } } } return false; }