function resize($source_name, $width = "", $height = "", $save_name = "") { $resource = NewMagickWand(); MagickReadImage($resource, $source_name); $src_image_x = MagickGetImageWidth($resource); $src_image_y = MagickGetImageHeight($resource); $src_image_scale = $src_image_x / $src_image_y; if ($width && $height) { $new_image_x = $width; $new_image_y = $height; } else { if ($width) { $new_image_x = $width; $new_image_y = $new_image_x * ($src_image_y / $src_image_x); } else { $new_image_y = $height; $new_image_x = $new_image_y * ($src_image_x / $src_image_y); } } MagickResizeImage($resource, $new_image_x, $new_image_y, MW_BoxFilter, 1); if ($save_name) { MagickWriteImage($resource, $save_name); } else { header('Content-Type: image/jpeg'); MagickEchoImageBlob($resource); } DestroymagickWand($resource); }
/** * @return Uploader */ public function prepare() { if (is_array($this->session)) { $this->digital = (string) $this->session['digital']; $this->public = (bool) $this->session['fg_publico']; } else { throw new Exception('Não foi possível recuperar os dados da sessão!'); } if ($this->_isFile()) { $this->hash = (string) hash_file('md5', $this->file["tmp_name"]); $this->type = (string) substr($this->file["name"], -3); $this->size = (int) $this->file["size"]; try { MagickReadImage($object = NewMagickWand(), $this->file["tmp_name"]); $this->width = MagickGetImageWidth($object); $this->height = MagickGetImageHeight($object); $this->codeType = MagickGetImageFormat($object); $this->sizeBytes = MagickGetImageSize($object); $this->compression = MagickGetImageCompression($object); $this->compressionQuality = MagickGetImageCompressionQuality($object); $this->resolution = MagickGetImageResolution($object); $this->resolutionUnits = MagickGetImageUnits($object); } catch (Exception $e) { throw new Exception('Ocorreu um erro!'); } } else { throw new Exception('O arquivo está ausente!'); } return $this; }
/** * 获取图片宽度 */ public function getWidth() { return MagickGetImageWidth(self::$resource); }
/** * liberty_magickwand_panorama_image - strictly speaking, this belongs in one of the image processing plugin files, but we'll leave it here for the moment * * @param array $pFileHash File hash - souce_file is required * @param array $pOptions * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function liberty_magickwand_panorama_image(&$pFileHash, $pOptions = array()) { $magickWand = NewMagickWand(); $pFileHash['error'] = NULL; if (!empty($pFileHash['source_file']) && is_file($pFileHash['source_file'])) { if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickReadImage($magickWand, $pFileHash['source_file']), $magickWand))) { // calculate border width $iwidth = round(MagickGetImageWidth($magickWand)); $iheight = round(MagickGetImageHeight($magickWand)); $aspect = $iwidth / $iheight; $metaHash = array('width' => $iwidth, 'height' => $iheight, 'aspect' => $aspect); // store original file information that we can adjust the viewer LibertyMime::storeMetaData($pFileHash['attachment_id'], 'PANO', $metaHash); // we need to pad the image if the aspect ratio is not 2:1 (give it a wee bit of leeway that we don't add annoying borders if not really needed) if ($aspect > 2.1 || $aspect < 1.9) { $bwidth = $bheight = 0; if ($aspect > 2) { $bheight = round(($iwidth / 2 - $iheight) / 2); } else { $bwidth = round(($iheight / 2 - $iwidth) / 2); } // if the ratio has nothing to do with a panorama image - i.e. gives us a negative number here, we won't generate a panorama image if ($bheight > 0) { $pixelWand = NewPixelWand(); PixelSetColor($pixelWand, !empty($pOptions['background']) ? $pOptions['background'] : 'black'); if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickBorderImage($magickWand, $pixelWand, $bwidth, $bheight), $magickWand))) { if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickWriteImage($magickWand, $pFileHash['source_file']), $magickWand))) { // yay! } } DestroyPixelWand($pixelWand); } } } } DestroyMagickWand($magickWand); return empty($pFileHash['error']); }
/** * Open the source and target image for processing it * * @param Asido_TMP &$tmp * @return boolean * @access protected */ function __open(&$tmp) { $tmp->source = NewMagickWand(); $error_open = !MagickReadImage($tmp->source, $tmp->source_filename); $error_open &= !($tmp->target = CloneMagickWand($tmp->source)); // get width & height of the image // if (!$error_open) { $tmp->image_width = MagickGetImageWidth($tmp->source); $tmp->image_height = MagickGetImageHeight($tmp->source); } return !$error_open; }
/** * liberty_magickwand_resize_image * * @param array $pFileHash * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function liberty_magickwand_resize_image(&$pFileHash) { global $gBitSystem; // static var here is crucial static $rgbConverts = array(); $magickWand = NewMagickWand(); $pFileHash['error'] = NULL; $ret = NULL; if (!empty($pFileHash['source_file']) && is_file($pFileHash['source_file']) && filesize($pFileHash['source_file'])) { if ($error = liberty_magickwand_check_error(MagickReadImage($magickWand, $pFileHash['source_file']), $magickWand)) { // $pFileHash['error'] = $error; $destFile = liberty_process_generic($pFileHash, FALSE); } else { if (MagickGetImageColorspace($magickWand) == MW_CMYKColorspace) { // These two lines are a hack needed for version of Ghostscript less that 8.60 MagickRemoveImageProfile($magickWand, "ICC"); MagickSetImageProfile($magickWand, 'ICC', file_get_contents(UTIL_PKG_PATH . 'icc/USWebCoatedSWOP.icc')); MagickProfileImage($magickWand, 'ICC', file_get_contents(UTIL_PKG_PATH . 'icc/srgb.icm')); MagickSetImageColorspace($magickWand, MW_RGBColorspace); $pFileHash['colorspace_conversion'] = TRUE; } MagickSetImageCompressionQuality($magickWand, $gBitSystem->getConfig('liberty_thumbnail_quality', 85)); $iwidth = round(MagickGetImageWidth($magickWand)); $iheight = round(MagickGetImageHeight($magickWand)); // this does not seem to be needed. magickwand will work out what to do by using the destination file extension //MagickSetImageFormat( $magickWand, $format ); if (empty($pFileHash['max_width']) && empty($pFileHash['max_height']) || !empty($pFileHash['max_width']) && $pFileHash['max_width'] == MAX_THUMBNAIL_DIMENSION || !empty($pFileHash['max_height']) && $pFileHash['max_height'] == MAX_THUMBNAIL_DIMENSION) { $pFileHash['max_width'] = $iwidth; $pFileHash['max_height'] = $iheight; } elseif ($iheight && $iwidth / $iheight < 1 && !empty($pFileHash['max_width']) && !empty($pFileHash['max_height'])) { // we have a portrait image, flip everything $temp = $pFileHash['max_width']; $pFileHash['max_height'] = $pFileHash['max_width']; $pFileHash['max_width'] = round($iwidth / $iheight * $pFileHash['max_height']); } elseif (!empty($pFileHash['max_width'])) { $pFileHash['max_height'] = round($iheight / $iwidth * $pFileHash['max_width']); } elseif (!empty($pFileHash['max_height'])) { $pFileHash['max_width'] = round($iwidth / $iheight * $pFileHash['max_height']); } // Make sure not to scale up if ($pFileHash['max_width'] > $iwidth && $pFileHash['max_height'] > $iheight) { $pFileHash['max_width'] = $iwidth; $pFileHash['max_height'] = $iheight; } // override $mimeExt if we have a custom setting for it if ($gBitSystem->isFeatureActive('liberty_thumbnail_format')) { $mimeExt = $gBitSystem->getConfig('liberty_thumbnail_format'); } elseif ($itype = MagickGetImageMimeType($magickWand)) { list($type, $mimeExt) = preg_split('#/#', strtolower($itype)); } else { list($type, $mimeExt) = preg_split('#/#', strtolower($pFileHash['type'])); } $replaced = FALSE; $mimeExt = preg_replace("!^(x-)?(jpeg|png|gif)\$!", "\$2", $mimeExt, -1, $replaced); if ($replaced) { $targetType = $mimeExt; $destExt = '.' . $mimeExt; } if (empty($destExt) || $mimeExt == 'jpeg') { $targetType = 'jpeg'; $destExt = '.jpg'; } if (!empty($pFileHash['dest_file'])) { $destFile = $pFileHash['dest_file']; } else { $destFile = STORAGE_PKG_PATH . $pFileHash['dest_branch'] . $pFileHash['dest_base_name'] . $destExt; } if (!empty($pFileHash['max_width']) && !empty($pFileHash['max_height']) && ($pFileHash['max_width'] < $iwidth || $pFileHash['max_height'] < $iheight || $mimeExt != $targetType) || !empty($pFileHash['colorspace_conversion'])) { $pFileHash['name'] = $pFileHash['dest_base_name'] . $destExt; // Alternate Filter settings can seen here http://www.dylanbeattie.net/magick/filters/result.html if ($error = liberty_magickwand_check_error(MagickResizeImage($magickWand, $pFileHash['max_width'], $pFileHash['max_height'], MW_CatromFilter, 1.0), $magickWand)) { $pFileHash['error'] .= $error; } if ($error = liberty_magickwand_check_error(MagickWriteImage($magickWand, $destFile), $magickWand)) { $pFileHash['error'] .= $error; } $pFileHash['size'] = filesize($destFile); } else { copy($pFileHash['source_file'], $destFile); } } $ret = $destFile; } else { $pFileHash['error'] = "No source file to resize"; } DestroyMagickWand($magickWand); return $ret; }
/** * liberty_generate_thumbnails * * @param array $pFileHash * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function liberty_generate_thumbnails($pFileHash) { global $gBitSystem, $gThumbSizes; $resizeFunc = liberty_get_function('resize'); $ret = FALSE; // allow custom selection of thumbnail sizes if (empty($pFileHash['thumbnail_sizes'])) { if (!empty($gThumbSizes) && is_array($gThumbSizes)) { $pFileHash['thumbnail_sizes'] = array_keys($gThumbSizes); } else { $pFileHash['thumbnail_sizes'] = array('large', 'medium', 'small', 'avatar', 'icon'); } } if (!preg_match('#image/(gif|jpe?g|png)#i', $pFileHash['type']) && $gBitSystem->isFeatureActive('liberty_jpeg_originals') || in_array('original', $pFileHash['thumbnail_sizes'])) { // jpeg version of original if (preg_match('/pdf/i', $pFileHash['type'])) { // has a customer pdf rasterization function been defined? if (function_exists('liberty_rasterize_pdf') && ($rasteredFile = liberty_rasterize_pdf($pFileHash['source_file']))) { $pFileHash['source_file'] = $rasteredFile; } else { $magickWand = NewMagickWand(); if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickReadImage($magickWand, $pFileHash['source_file']), $magickWand))) { MagickSetFormat($magickWand, 'JPG'); if (MagickGetImageColorspace($magickWand) == MW_CMYKColorspace) { MagickProfileImage($magickWand, "ICC", UTIL_PKG_PATH . 'icc/srgb.icm'); MagickSetImageColorspace($magickWand, MW_sRGBColorspace); } $imgWidth = MagickGetImageWidth($magickWand); $imgHeight = MagickGetImageHeight($magickWand); MagickSetImageUnits($magickWand, MW_PixelsPerInchResolution); MagickSetResolution($magickWand, 300, 300); $rasteredFile = dirname($pFileHash['source_file']) . '/original.jpg'; if (!($pFileHash['error'] = liberty_magickwand_check_error(MagickWriteImage($magickWand, $rasteredFile), $magickWand))) { $pFileHash['source_file'] = $rasteredFile; } } } } else { $pFileHash['dest_base_name'] = 'original'; $pFileHash['name'] = 'original.jpg'; $pFileHash['max_width'] = MAX_THUMBNAIL_DIMENSION; $pFileHash['max_height'] = MAX_THUMBNAIL_DIMENSION; if ($convertedFile = $resizeFunc($pFileHash)) { $pFileHash['source_file'] = $convertedFile; $ret = TRUE; } } $pFileHash['type'] = $gBitSystem->verifyMimeType($pFileHash['source_file']); } // override $mimeExt if we have a custom setting for it if ($gBitSystem->isFeatureActive('liberty_thumbnail_format')) { $mimeExt = $gBitSystem->getConfig('liberty_thumbnail_format'); } else { list($type, $mimeExt) = preg_split('#/#', strtolower($pFileHash['type'])); } if (preg_match("!(png|gif)!", $mimeExt)) { $destExt = '.' . $mimeExt; } else { $destExt = '.jpg'; } $initialDestPath = $pFileHash['dest_branch']; foreach ($pFileHash['thumbnail_sizes'] as $thumbSize) { if (isset($gThumbSizes[$thumbSize])) { $pFileHash['dest_base_name'] = $thumbSize; $pFileHash['name'] = $thumbSize . $destExt; if (!empty($gThumbSizes[$thumbSize]['width'])) { $pFileHash['max_width'] = $gThumbSizes[$thumbSize]['width']; } else { // Have to unset since we reuse $pFileHash unset($pFileHash['max_width']); } // reset dest_branch for created thumbs if (!empty($pFileHash['thumb_path'])) { $pFileHash['dest_file'] = $pFileHash['thumb_path'] . $pFileHash['name']; } else { // create a subdirectory for the thumbs $pFileHash['dest_branch'] = $initialDestPath . 'thumbs/'; clearstatcache(); if (!is_dir(STORAGE_PKG_PATH . $pFileHash['dest_branch'])) { mkdir(STORAGE_PKG_PATH . $pFileHash['dest_branch'], 0775, TRUE); clearstatcache(); } } if (!empty($gThumbSizes[$thumbSize]['height'])) { $pFileHash['max_height'] = $gThumbSizes[$thumbSize]['height']; } else { // Have to unset since we reuse $pFileHash unset($pFileHash['max_height']); } if ($pFileHash['icon_thumb_path'] = $resizeFunc($pFileHash)) { $ret = TRUE; // use the previous thumb as the source for the next, decreasingly smaller thumb as this GREATLY increases speed $pFileHash['source_file'] = $pFileHash['icon_thumb_path']; } } } // to keep everything in bitweaver working smoothly, we need to remove the thumbs/ subdir again $pFileHash['dest_branch'] = $initialDestPath; return $ret; }
protected function generateMW() { if (file_exits($this->pathcache . $this->getBaseName())) { return true; } $img = NewMagickWand(); MagickReadImage($img, $this->pathname . $this->filename); $this->info = array('width' => MagickGetImageWidth($img), 'height' => MagickGetImageHeight($img), 'duration' => 0, 'mime' => $this->mime, 'size' => filesize($this->pathname . $this->filename)); MagickSetImageFormat($img, 'JPEG'); MagickWriteImage($img, $this->pathcache . $this->getBaseName()); $this->mime = 'image/jpeg'; $this->type = array('image', 'jpeg'); $this->pathname = $this->pathcache; $this->filename = $this->getBaseName(); return true; }
public function convert($ps_format, $ps_orig_filepath, $ps_dest_filepath) { $vs_filepath = $vs_ext = ""; # # First make sure the original file is an image # if (!($vs_mimetype = $this->test($ps_orig_filepath, ""))) { return false; } if ($vs_mimetype == "application/pdf") { return false; } $va_dest_path_pieces = explode("/", $ps_dest_filepath); $vs_dest_filestem = array_pop($va_dest_path_pieces); $vs_dest_dir = join("/", $va_dest_path_pieces); $vn_width = $vn_height = null; switch ($ps_format) { # ------------------------------------ case 'image/jpeg': $vs_ext = "jpg"; $vs_filepath = $vs_dest_filestem . "_conv." . $vs_ext; switch ($this->backend) { case LIBRARY_GD: if ($vs_mimetype = $this->test($ps_orig_filepath)) { switch ($vs_mimetype) { case "image/jpeg": $rsource = imagecreatefromjpeg($ps_orig_filepath); break; case "image/png": $rsource = imagecreatefrompng($ps_orig_filepath); break; case "image/gif": $rsource = imagecreatefromgif($ps_orig_filepath); break; default: return false; break; } if (!$r) { return false; } list($vn_width, $vn_height) = getimagesize($ps_orig_filepath); if ($vn_width > $vn_height) { $vn_ratio = $vn_height / $vn_width; $vn_target_width = 800; $vn_target_height = 800 * $vn_ratio; } else { $vn_ratio = $vn_width / $vn_height; $vn_target_height = 800; $vn_target_width = 800 * $vn_ratio; } if (!($rdest = imagecreatetruecolor($vn_target_width, $vn_target_height))) { return false; } if (!imagecopyresampled($rdest, $rsource, 0, 0, 0, 0, $vn_target_width, $vn_target_height, $vn_width, $vn_height)) { return false; } if (!imagejpeg($rdest, $vs_dest_dir . "/" . $vs_filepath)) { return false; } } else { return false; } break; default: $handle = NewMagickWand(); if (MagickReadImage($handle, $ps_orig_filepath)) { if (WandHasException($handle)) { return false; } $vn_width = MagickGetImageWidth($handle); $vn_height = MagickGetImageHeight($handle); if ($vn_width > $vn_height) { $vn_ratio = $vn_height / $vn_width; $vn_target_width = 800; $vn_target_height = 800 * $vn_ratio; } else { $vn_ratio = $vn_width / $vn_height; $vn_target_height = 800; $vn_target_width = 800 * $vn_ratio; } if (!MagickResizeImage($handle, $vn_target_width, $vn_target_height, MW_CubicFilter, 1)) { return false; } if (!MagickWriteImage($handle, $vs_dest_dir . "/" . $vs_filepath)) { return false; } } break; } break; # ------------------------------------ # ------------------------------------ default: return false; break; # ------------------------------------ } return array("extension" => $vs_ext, "format_name" => $this->info["CONVERSIONS"][$ps_format]["format_name"], "dangerous" => 0, "width" => $vn_width, "height" => $vn_height, "long_format_name" => $this->info["CONVERSIONS"][$ps_format]["long_format_name"]); }
private function createAndUploadImageDimensionMap(Image $image, $dimensionsKeyname) { $imd = $this->getDimensionByKeyname($dimensionsKeyname); $srcPth = $this->imagesRoot . $image->FilePath; if (file_exists($srcPth)) { $tempPath = tempnam(sys_get_temp_dir(), 'img_'); if ($dimensionsKeyname == 'original') { $s3Path = $srcPth; $pts = getimagesize($s3Path); $width = $pts[0]; $height = $pts[1]; $newDims = array('x' => $width, 'y' => $height); $s3Path = $srcPth; } else { //need to redimension this image, using MagickWand $magick_wand = NewMagickWand(); MagickReadImage($magick_wand, $srcPth); $width = MagickGetImageWidth($magick_wand); $height = MagickGetImageHeight($magick_wand); $newDims = $this->getNewDimensionsPreservingAspectRatio($width, $height, $imd->Width, $imd->Height); MagickScaleImage($magick_wand, $newDims['x'], $newDims['y']); MagickWriteImage($magick_wand, $tempPath); $s3Path = $tempPath; } $headers = array(); //This holds the http headers for our S3 object. switch ($image->ImageType) { case 'GIF': $headers['Content-Type'] = 'image/gif'; break; case 'JPG': $headers['Content-Type'] = 'image/jpeg'; break; case 'PNG': $headers['Content-Type'] = 'image/png'; break; default: throw new Exception("Unrecognized type {$image->getType()}"); break; } //A "Far Future" expiration - maximizing the chance that the user's web browser will use //a cached version rather than requesting the file from Cloudfront. //Also set to public (as recommended by Google Speed Tracer), so that caching will work when //using SSL as well. Even though Cloudfont doesn't support ssl today, someday it will //and we will be prepared! $headers['Cache-Control'] = 'public, max-age=315360000'; //10 years $imDimMap = new ImageDimensionsMap(); $imDimMap->ImageId = $image->Id; $imDimMap->ImageDimensionsId = $imd->Id; $imDimMap->Width = $newDims['x']; $imDimMap->Height = $newDims['y']; $imDimMap->Version = $image->Version; $imDimMap->save(); //upload the new file to S3 try { $acl = S3Service::ACL_PUBLIC_READ; if (!file_exists($tempPath)) { throw new Exception("{$tempPath} dosn't exist"); } $res = $this->s3->putObject(S3Service::inputFile($s3Path, true), $this->bucket, $this->getPath($image, $imDimMap, $imd), $acl, array(), $headers); if ($res) { unlink($tempPath); } else { //something's wrong. Fail silently and just leave the old version if it exists. //Don't throw an exception or raise a failure, because there's a user on the other side //of this request waiting to see this image. $imDimMap->Version = $imDimMap->Version - 1; $imDimMap->save(); } } catch (Exception $e) { //something's wrong. Fail silently and just leave the old version if it exist. //Don't throw an exception or raise a failure, because there's a user on the other side //of this request waiting to see this image. $imDimMap->Version = $imDimMap->Version - 1; $imDimMap->save(); } } return $imDimMap; }
public function addPicWatermark($srcFile, $wmFile, $desFile = "", $mode = 5) { if (empty($desFile) && !$this->direct_show) { $desFile = $srcFile; } if (!file_exists($srcFile) || !file_exists($wmFile)) { return false; } $img = $this->getImgWand($srcFile); $width = MagickGetImageWidth($img); $height = MagickGetImageHeight($img); $img_mw = $this->getImgWand($wmFile); $img_mw = $this->resizePic($img_mw, $width / 4, $height / 4); switch ($mode) { case 1: $offset_x = 0; $offset_y = 0; break; case 2: $offset_x = $width - MagickGetImageWidth($img_mw); $offset_y = 0; break; case 3: $offset_x = ($width - MagickGetImageWidth($img_mw)) / 2; $offset_y = ($height - MagickGetImageHeight($img_mw)) / 2; break; case 4: $offset_x = 0; $offset_y = $height - MagickGetImageHeight($img_mw); break; case 5: $offset_x = $width - MagickGetImageWidth($img_mw); $offset_y = $height - MagickGetImageHeight($img_mw); break; default: if (is_array($mode) && count($mode) == 2) { $offset_x = $mode[0]; $offset_y = $mode[1]; } else { $offset_x = $width - MagickGetImageWidth($img_mw); $offset_y = $height - MagickGetImageHeight($img_mw); } break; } $this->batchModify($img, "MagickCompositeImage", array($img_mw, MW_AtopCompositeOp, $offset_x, $offset_y)); $this->destoryWand($img_mw); $this->generateImg($img, $desFile); return true; }
function getPos($sourcefile_width, $sourcefile_height, $pos, $wm_image = "") { if ($wm_image) { $insertfile_width = MagickGetImageWidth($wm_image); $insertfile_height = MagickGetImageHeight($wm_image); } switch ($pos) { case 0: $dest_x = $sourcefile_width / 2 - $insertfile_width / 2; $dest_y = $sourcefile_height / 2 - $insertfile_height / 2; break; case 1: $dest_x = 0; if ($this->wm_text) { $dest_y = $insertfile_height; } else { $dest_y = 0; } break; case 2: $dest_x = $sourcefile_width - $insertfile_width; if ($this->wm_text) { $dest_y = $insertfile_height; } else { $dest_y = 0; } break; case 3: $dest_x = $sourcefile_width - $insertfile_width; $dest_y = $sourcefile_height - $insertfile_height; break; case 4: $dest_x = 0; $dest_y = $sourcefile_height - $insertfile_height; break; case 5: $dest_x = ($sourcefile_width - $insertfile_width) / 2; if ($this->wm_text) { $dest_y = $insertfile_height; } else { $dest_y = 0; } break; case 6: $dest_x = $sourcefile_width - $insertfile_width; $dest_y = $sourcefile_height / 2 - $insertfile_height / 2; break; case 7: $dest_x = ($sourcefile_width - $insertfile_width) / 2; $dest_y = $sourcefile_height - $insertfile_height; break; case 8: $dest_x = 0; $dest_y = $sourcefile_height / 2 - $insertfile_height / 2; break; default: $dest_x = $sourcefile_width - $insertfile_width; $dest_y = $sourcefile_height - $insertfile_height; break; } return array("dest_x" => $dest_x, "dest_y" => $dest_y); }
/** * @return Imagens * @param string $digital * @param string $md5 * @param boolean $high * @param int $active * @param int $total */ public function createCacheJpegView($digital, $md5, $high = false) { $iImageHeightPixel = $high === false ? 960 : 2480; $iImageWidthPixel = $high === false ? 1280 : 3508; $lote = $this->generateLote($digital); $dirCache = sprintf('%s/cache/%s', __CAM_UPLOAD__, $lote); $tiff = sprintf('%s/%s/%s/%s.tif', __CAM_UPLOAD__, $lote, $digital, $md5); $view = sprintf('%s/%s/%s_view_%d.jpg', $dirCache, $digital, $md5, $high === false ? self::Q_LOW : self::Q_HIGH); $thumbs = sprintf('%s/%s/%s_thumb.jpg', $dirCache, $digital, $md5); if (!is_file($tiff)) { throw new Exception('Arquivo TIFF original não encontrado!'); } if (is_file($view)) { return $this; } // thumbs if (!is_file($thumbs)) { MagickReadImage($magickThumbs = NewMagickWand(), $tiff); if (MagickGetImageWidth($magickThumbs) < MagickGetImageHeight($magickThumbs)) { MagickResizeImage($magickThumbs, 150, 200, MW_QuadraticFilter, 1.0); } else { MagickResizeImage($magickThumbs, 200, 150, MW_QuadraticFilter, 1.0); } MagickSetImageFormat($magickThumbs, 'JPG'); MagickSetImageResolution($magickThumbs, 200, 200); MagickSetImageUnits($magickThumbs, MW_PixelsPerInchResolution); MagickSetImageCompression($magickThumbs, MW_JPEGCompression); MagickSetImageCompressionQuality($magickThumbs, 0.0); MagickWriteImage($magickThumbs, $thumbs); } // views MagickReadImage($magickView = NewMagickWand(), $tiff); if (MagickGetImageWidth($magickView) > MagickGetImageHeight($magickView)) { MagickResizeImage($magickView, $iImageWidthPixel, $iImageHeightPixel, MW_QuadraticFilter, 1.0); } else { MagickResizeImage($magickView, $iImageHeightPixel, $iImageWidthPixel, MW_QuadraticFilter, 1.0); } MagickSetImageFormat($magickView, 'JPG'); MagickSetImageResolution($magickView, 200, 200); MagickSetImageUnits($magickView, MW_PixelsPerInchResolution); MagickSetImageCompression($magickView, MW_JPEGCompression); MagickSetImageCompressionQuality($magickView, 0.0); MagickWriteImage($magickView, $view); $errorMagick = MagickGetExceptionString($magickView); if ($errorMagick) { throw new Exception($errorMagick); } return $this; }