当前位置: 首页>>代码示例>>PHP>>正文


PHP imagick::resizeImage方法代码示例

本文整理汇总了PHP中imagick::resizeImage方法的典型用法代码示例。如果您正苦于以下问题:PHP imagick::resizeImage方法的具体用法?PHP imagick::resizeImage怎么用?PHP imagick::resizeImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imagick的用法示例。


在下文中一共展示了imagick::resizeImage方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mkdir

 function cdm_thumbPdf($pdf)
 {
     if (class_exists('imagick')) {
         $upload_dir = wp_upload_dir();
         $tmp_folder = $upload_dir['basedir'] . '/imageMagick_tmp/';
         if (!is_dir($tmp_folder)) {
             mkdir($tmp_folder, 0777);
         }
         $tmp = $tmp_folder;
         $format = "png";
         $source = $pdf;
         $dest = "" . $pdf . "_big.{$format}";
         $dest2 = "" . $pdf . "_small.{$format}";
         // read page 1
         $im = new imagick('' . $source . '[0]');
         // convert to jpg
         $im->setImageColorspace(255);
         $im->setImageFormat($format);
         //resize
         $im->resizeImage(650, 650, imagick::FILTER_LANCZOS, 1);
         //write image on server
         $im->writeImage($dest);
         //resize
         $im->resizeImage(250, 250, imagick::FILTER_LANCZOS, 1);
         //write image on server
         $im->writeImage($dest2);
         $im->clear();
         $im->destroy();
     } else {
         echo 'php-image-magick not installed. Please disable the pdf thumbnail options or install the php extention correctly.';
         exit;
     }
 }
开发者ID:beafus,项目名称:Living-Meki-Platform,代码行数:33,代码来源:functions.php

示例2: imgResize

 /**
  * Resize image
  *
  * @param  string   $path               image file
  * @param  int      $width              new width
  * @param  int      $height             new height
  * @param  bool	    $keepProportions    crop image
  * @param  bool	    $resizeByBiggerSide resize image based on bigger side if true
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author Dmitry (dio) Levashov
  * @author Alexey Sukhotin
  **/
 protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null)
 {
     if (($s = @getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     list($size_w, $size_h) = array($width, $height);
     if ($keepProportions == true) {
         list($orig_w, $orig_h, $new_w, $new_h) = array($s[0], $s[1], $width, $height);
         /* Calculating image scale width and height */
         $xscale = $orig_w / $new_w;
         $yscale = $orig_h / $new_h;
         /* Resizing by biggest side */
         if ($resizeByBiggerSide) {
             if ($orig_w > $orig_h) {
                 $size_h = $orig_h * $width / $orig_w;
                 $size_w = $width;
             } else {
                 $size_w = $orig_w * $height / $orig_h;
                 $size_h = $height;
             }
         } else {
             if ($orig_w > $orig_h) {
                 $size_w = $orig_w * $height / $orig_h;
                 $size_h = $height;
             } else {
                 $size_h = $orig_h * $width / $orig_w;
                 $size_w = $width;
             }
         }
     }
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             $img->resizeImage($size_w, $size_h, Imagick::FILTER_LANCZOS, true);
             $result = $img->writeImage($path);
             return $result ? $path : false;
             break;
         case 'gd':
             if ($s['mime'] == 'image/jpeg') {
                 $img = imagecreatefromjpeg($path);
             } elseif ($s['mime'] == 'image/png') {
                 $img = imagecreatefrompng($path);
             } elseif ($s['mime'] == 'image/gif') {
                 $img = imagecreatefromgif($path);
             } elseif ($s['mime'] == 'image/xbm') {
                 $img = imagecreatefromxbm($path);
             }
             if ($img && false != ($tmp = imagecreatetruecolor($size_w, $size_h))) {
                 if (!imagecopyresampled($tmp, $img, 0, 0, 0, 0, $size_w, $size_h, $s[0], $s[1])) {
                     return false;
                 }
                 if ($destformat == 'jpg' || $destformat == null && $s['mime'] == 'image/jpeg') {
                     $result = imagejpeg($tmp, $path, 100);
                 } else {
                     if ($destformat == 'gif' || $destformat == null && $s['mime'] == 'image/gif') {
                         $result = imagegif($tmp, $path, 7);
                     } else {
                         $result = imagepng($tmp, $path, 7);
                     }
                 }
                 imagedestroy($img);
                 imagedestroy($tmp);
                 return $result ? $path : false;
             }
             break;
     }
     return false;
 }
开发者ID:serhatozles,项目名称:yii2-elfinder,代码行数:86,代码来源:elFinderVolumeDriver.class.php

示例3: createTmb

 protected function createTmb($vd6fe1d0be6347b8ef2427fa629c04485)
 {
     $vd02a169f33469c888396a24dd9d9f1c6 = $this->mimetype($vd6fe1d0be6347b8ef2427fa629c04485);
     if (!$this->canCreateTmb($vd6fe1d0be6347b8ef2427fa629c04485, $vd02a169f33469c888396a24dd9d9f1c6)) {
         return false;
     }
     $vb068931cc450442b63f5b3d276ea4297 = $this->tmbName($vd6fe1d0be6347b8ef2427fa629c04485);
     $va8b687c2e93191d90a6d7b8982ceec4a = $this->tmbPath . DIRECTORY_SEPARATOR . $vb068931cc450442b63f5b3d276ea4297;
     if (($v25d902c24283ab8cfbac54dfa101ad31 = $this->_fopen($vd6fe1d0be6347b8ef2427fa629c04485, 'rb')) == false || ($v90710761341352a9e144d8ad4c92598b = @fopen($va8b687c2e93191d90a6d7b8982ceec4a, 'wb')) == false) {
         return false;
     }
     while (!feof($v25d902c24283ab8cfbac54dfa101ad31)) {
         fwrite($v90710761341352a9e144d8ad4c92598b, fread($v25d902c24283ab8cfbac54dfa101ad31, 8192));
     }
     $this->_fclose($v25d902c24283ab8cfbac54dfa101ad31, $vd6fe1d0be6347b8ef2427fa629c04485);
     fclose($v90710761341352a9e144d8ad4c92598b);
     if (($v03c7c0ace395d80182db07ae2c30f034 = @getimagesize($va8b687c2e93191d90a6d7b8982ceec4a)) == false) {
         return false;
     }
     $result = false;
     $v88029fd68f54ae31758f44d7b965868f = $this->tmbSize;
     list($v9dd4e461268c8034f5c8564e155c67a6, $v415290769594460e2e485922904f345d, $v84b16781293d33e80d74ef9d63280bc0, $v55fc30b57cc1b80e8f68104931fbf716) = $this->tmbEffects($v03c7c0ace395d80182db07ae2c30f034[0], $v03c7c0ace395d80182db07ae2c30f034[1], $v88029fd68f54ae31758f44d7b965868f, $this->options['tmbCrop']);
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $vb798abe6e1b1318ee36b0dcb3fb9e4d3 = new imagick($va8b687c2e93191d90a6d7b8982ceec4a);
             } catch (Exception $ve1671797c52e15f763380b45e841ec32) {
                 return false;
             }
             $vb798abe6e1b1318ee36b0dcb3fb9e4d3->contrastImage(1);
             if ($this->options['tmbCrop'] == false) {
                 $va8a63b4d63a08aed720d0f5f249e07d9 = new Imagick();
                 $va8a63b4d63a08aed720d0f5f249e07d9->newImage($v88029fd68f54ae31758f44d7b965868f, $v88029fd68f54ae31758f44d7b965868f, new ImagickPixel($this->options['tmbBgColor']));
                 $va8a63b4d63a08aed720d0f5f249e07d9->setImageFormat('png');
                 $vb798abe6e1b1318ee36b0dcb3fb9e4d3->resizeImage($v84b16781293d33e80d74ef9d63280bc0, $v55fc30b57cc1b80e8f68104931fbf716, NULL, true);
                 $va8a63b4d63a08aed720d0f5f249e07d9->compositeImage($vb798abe6e1b1318ee36b0dcb3fb9e4d3, imagick::COMPOSITE_OVER, $v9dd4e461268c8034f5c8564e155c67a6, $v415290769594460e2e485922904f345d);
                 $result = $va8a63b4d63a08aed720d0f5f249e07d9->writeImage($va8b687c2e93191d90a6d7b8982ceec4a);
             } else {
                 $result = $vb798abe6e1b1318ee36b0dcb3fb9e4d3->cropThumbnailImage($v88029fd68f54ae31758f44d7b965868f, $v88029fd68f54ae31758f44d7b965868f) && $vb798abe6e1b1318ee36b0dcb3fb9e4d3->writeImage($va8b687c2e93191d90a6d7b8982ceec4a);
             }
             break;
         case 'gd':
             if ($v03c7c0ace395d80182db07ae2c30f034['mime'] == 'image/jpeg') {
                 $vb798abe6e1b1318ee36b0dcb3fb9e4d3 = imagecreatefromjpeg($va8b687c2e93191d90a6d7b8982ceec4a);
             } elseif ($v03c7c0ace395d80182db07ae2c30f034['mime'] == 'image/png') {
                 $vb798abe6e1b1318ee36b0dcb3fb9e4d3 = imagecreatefrompng($va8b687c2e93191d90a6d7b8982ceec4a);
             } elseif ($v03c7c0ace395d80182db07ae2c30f034['mime'] == 'image/gif') {
                 $vb798abe6e1b1318ee36b0dcb3fb9e4d3 = imagecreatefromgif($va8b687c2e93191d90a6d7b8982ceec4a);
             } elseif ($v03c7c0ace395d80182db07ae2c30f034['mime'] == 'image/xbm') {
                 $vb798abe6e1b1318ee36b0dcb3fb9e4d3 = imagecreatefromxbm($va8b687c2e93191d90a6d7b8982ceec4a);
             }
             if (isset($vb798abe6e1b1318ee36b0dcb3fb9e4d3) && $vb798abe6e1b1318ee36b0dcb3fb9e4d3 && false != ($vfa816edb83e95bf0c8da580bdfd491ef = imagecreatetruecolor($v88029fd68f54ae31758f44d7b965868f, $v88029fd68f54ae31758f44d7b965868f))) {
                 if ($this->options['tmbCrop'] == false) {
                     if ($this->options['tmbBgColor'] == 'transparent') {
                         list($v4b43b0aee35624cd95b910189b3dc231, $vb2f5ff47436671b6e533d8dc3614845d, $v92eb5ffee6ae2fec3ad71c777531578f) = array(0, 0, 255);
                     } else {
                         list($v4b43b0aee35624cd95b910189b3dc231, $vb2f5ff47436671b6e533d8dc3614845d, $v92eb5ffee6ae2fec3ad71c777531578f) = sscanf($this->options['tmbBgColor'], "#%02x%02x%02x");
                     }
                     $ve12224dadfacf7a79886df59f202a403 = imagecolorallocate($vfa816edb83e95bf0c8da580bdfd491ef, $v4b43b0aee35624cd95b910189b3dc231, $vb2f5ff47436671b6e533d8dc3614845d, $v92eb5ffee6ae2fec3ad71c777531578f);
                     if ($this->options['tmbBgColor'] == 'transparent') {
                         $ve12224dadfacf7a79886df59f202a403 = imagecolortransparent($vfa816edb83e95bf0c8da580bdfd491ef, $ve12224dadfacf7a79886df59f202a403);
                     }
                     imagefill($vfa816edb83e95bf0c8da580bdfd491ef, 0, 0, $ve12224dadfacf7a79886df59f202a403);
                     if (!imagecopyresampled($vfa816edb83e95bf0c8da580bdfd491ef, $vb798abe6e1b1318ee36b0dcb3fb9e4d3, $v9dd4e461268c8034f5c8564e155c67a6, $v415290769594460e2e485922904f345d, 0, 0, $v84b16781293d33e80d74ef9d63280bc0, $v55fc30b57cc1b80e8f68104931fbf716, $v03c7c0ace395d80182db07ae2c30f034[0], $v03c7c0ace395d80182db07ae2c30f034[1])) {
                         return false;
                     }
                 } else {
                     if (!imagecopyresampled($vfa816edb83e95bf0c8da580bdfd491ef, $vb798abe6e1b1318ee36b0dcb3fb9e4d3, 0, 0, $v9dd4e461268c8034f5c8564e155c67a6, $v415290769594460e2e485922904f345d, $v88029fd68f54ae31758f44d7b965868f, $v88029fd68f54ae31758f44d7b965868f, $v84b16781293d33e80d74ef9d63280bc0, $v55fc30b57cc1b80e8f68104931fbf716)) {
                         return false;
                     }
                 }
                 $result = imagepng($vfa816edb83e95bf0c8da580bdfd491ef, $va8b687c2e93191d90a6d7b8982ceec4a, 7);
                 imagedestroy($vb798abe6e1b1318ee36b0dcb3fb9e4d3);
                 imagedestroy($vfa816edb83e95bf0c8da580bdfd491ef);
             }
             break;
     }
     return $result ? $vb068931cc450442b63f5b3d276ea4297 : false;
 }
开发者ID:BGCX261,项目名称:zimmerli-svn-to-git,代码行数:79,代码来源:elFinderVolumeDriver.class.php

示例4: _tmb

 /**
  * Create image thumbnail
  *
  * @param  string  $img  image file
  * @param  string  $tmb  thumbnail name
  * @return bool
  **/
 protected function _tmb($img, $tmb)
 {
     if (false == ($s = getimagesize($img))) {
         return false;
     }
     $tmbSize = $this->_options['tmbSize'];
     if ($this->_options['tmbCrop'] == false) {
         /* Calculating image scale width and height */
         $xscale = $s[0] / $tmbSize;
         $yscale = $s[1] / $tmbSize;
         if ($yscale > $xscale) {
             $newwidth = round($s[0] * (1 / $yscale));
             $newheight = round($s[1] * (1 / $yscale));
         } else {
             $newwidth = round($s[0] * (1 / $xscale));
             $newheight = round($s[1] * (1 / $xscale));
         }
         /* Keeping original dimensions if image fitting into thumbnail without scale */
         if ($s[0] <= $tmbSize && $s[1] <= $tmbSize) {
             $newwidth = $s[0];
             $newheight = $s[1];
         }
         /* Calculating coordinates for aligning thumbnail */
         $align_y = ceil(($tmbSize - $newheight) / 2);
         $align_x = ceil(($tmbSize - $newwidth) / 2);
     }
     switch ($this->_options['imgLib']) {
         case 'imagick':
             try {
                 $_img = new imagick($img);
             } catch (Exception $e) {
                 return false;
             }
             $_img->contrastImage(1);
             if ($this->_options['tmbCrop'] == false) {
                 $img1 = new Imagick();
                 $img1->newImage($tmbSize, $tmbSize, new ImagickPixel($this->_options['tmbBgColor']));
                 $img1->setImageFormat('png');
                 $_img->resizeImage($newwidth, $newheight, NULL, true);
                 $img1->compositeImage($_img, imagick::COMPOSITE_OVER, $align_x, $align_y);
                 return $img1->writeImage($tmb);
             } else {
                 return $_img->cropThumbnailImage($tmbSize, $tmbSize) && $_img->writeImage($tmb);
             }
             break;
         case 'mogrify':
             if (@copy($img, $tmb)) {
                 list($x, $y, $size) = $this->_cropPos($s[0], $s[1]);
                 // exec('mogrify -crop '.$size.'x'.$size.'+'.$x.'+'.$y.' -scale '.$tmbSize.'x'.$tmbSize.'! '.escapeshellarg($tmb), $o, $c);
                 $mogrifyArgs = 'mogrify -resize ' . $tmbSize . 'x' . $tmbSize;
                 if ($this->_options['tmbCrop'] == false) {
                     $mogrifyArgs .= ' -gravity center -background "' . $this->_options['tmbBgColor'] . '" -extent ' . $tmbSize . 'x' . $tmbSize;
                 }
                 if ($this->_options['tmbCrop'] == false) {
                     $mogrifyArgs .= ' ' . escapeshellarg($tmb);
                 }
                 exec($mogrifyArgs, $o, $c);
                 if (file_exists($tmb)) {
                     return true;
                 } elseif ($c == 0) {
                     // find tmb for psd and animated gif
                     $mime = $this->_mimetype($img);
                     if ($mime == 'image/vnd.adobe.photoshop' || ($mime = 'image/gif')) {
                         $pinfo = pathinfo($tmb);
                         $test = $pinfo['dirname'] . DIRECTORY_SEPARATOR . $pinfo['filename'] . '-0.' . $pinfo['extension'];
                         if (file_exists($test)) {
                             return rename($test, $tmb);
                         }
                     }
                 }
             }
             break;
         case 'gd':
             if ($s['mime'] == 'image/jpeg') {
                 $_img = imagecreatefromjpeg($img);
             } elseif ($s['mime'] == 'image/png') {
                 $_img = imagecreatefrompng($img);
             } elseif ($s['mime'] == 'image/gif') {
                 $_img = imagecreatefromgif($img);
             }
             if (!$_img || false == ($_tmb = imagecreatetruecolor($tmbSize, $tmbSize))) {
                 return false;
             }
             if ($this->_options['tmbCrop'] == false) {
                 list($r, $g, $b) = sscanf($this->_options['tmbBgColor'], "#%02x%02x%02x");
                 imagefill($_tmb, 0, 0, imagecolorallocate($_tmb, $r, $g, $b));
                 if (!imagecopyresampled($_tmb, $_img, $align_x, $align_y, 0, 0, $newwidth, $newheight, $s[0], $s[1])) {
                     return false;
                 }
             } else {
                 list($x, $y, $size) = $this->_cropPos($s[0], $s[1]);
                 if (!imagecopyresampled($_tmb, $_img, 0, 0, $x, $y, $tmbSize, $tmbSize, $size, $size)) {
                     return false;
//.........这里部分代码省略.........
开发者ID:hucongyang,项目名称:lulucms2,代码行数:101,代码来源:elFinder.class.php

示例5: imgResize

 /**
  * Resize image
  *
  * @param  string   $path               image file
  * @param  int      $width              new width
  * @param  int      $height             new height
  * @param  bool	    $keepProportions    crop image
  * @param  bool	    $resizeByBiggerSide resize image based on bigger side if true
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author Dmitry (dio) Levashov
  * @author Alexey Sukhotin
  **/
 protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null)
 {
     if (($s = @getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     list($size_w, $size_h) = array($width, $height);
     if ($keepProportions == true) {
         list($orig_w, $orig_h, $new_w, $new_h) = array($s[0], $s[1], $width, $height);
         /* Calculating image scale width and height */
         $xscale = $orig_w / $new_w;
         $yscale = $orig_h / $new_h;
         /* Resizing by biggest side */
         if ($resizeByBiggerSide) {
             if ($orig_w > $orig_h) {
                 $size_h = $orig_h * $width / $orig_w;
                 $size_w = $width;
             } else {
                 $size_w = $orig_w * $height / $orig_h;
                 $size_h = $height;
             }
         } else {
             if ($orig_w > $orig_h) {
                 $size_w = $orig_w * $height / $orig_h;
                 $size_h = $height;
             } else {
                 $size_h = $orig_h * $width / $orig_w;
                 $size_w = $width;
             }
         }
     }
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             $img->resizeImage($size_w, $size_h, Imagick::FILTER_LANCZOS, true);
             $result = $img->writeImage($path);
             return $result ? $path : false;
             break;
         case 'gd':
             $img = self::gdImageCreate($path, $s['mime']);
             if ($img && false != ($tmp = imagecreatetruecolor($size_w, $size_h))) {
                 self::gdImageBackground($tmp, $this->options['tmbBgColor']);
                 if (!imagecopyresampled($tmp, $img, 0, 0, 0, 0, $size_w, $size_h, $s[0], $s[1])) {
                     return false;
                 }
                 $result = self::gdImage($tmp, $path, $destformat, $s['mime']);
                 imagedestroy($img);
                 imagedestroy($tmp);
                 return $result ? $path : false;
             }
             break;
     }
     return false;
 }
开发者ID:hyrmedia,项目名称:builderengine,代码行数:71,代码来源:elFinderVolumeDriver.class.php

示例6: imgResize

 /**
  * Resize image
  *
  * @param  string   $path               image file
  * @param  int      $width              new width
  * @param  int      $height             new height
  * @param  bool	    $keepProportions    crop image
  * @param  bool	    $resizeByBiggerSide resize image based on bigger side if true
  * @param  string   $destformat         image destination format
  * @return string|false
  * @author Dmitry (dio) Levashov
  * @author Alexey Sukhotin
  **/
 protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null)
 {
     if (($s = @getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     list($size_w, $size_h) = array($width, $height);
     if ($keepProportions == true) {
         list($orig_w, $orig_h, $new_w, $new_h) = array($s[0], $s[1], $width, $height);
         /* Calculating image scale width and height */
         $xscale = $orig_w / $new_w;
         $yscale = $orig_h / $new_h;
         /* Resizing by biggest side */
         if ($resizeByBiggerSide) {
             if ($orig_w > $orig_h) {
                 $size_h = $orig_h * $width / $orig_w;
                 $size_w = $width;
             } else {
                 $size_w = $orig_w * $height / $orig_h;
                 $size_h = $height;
             }
         } else {
             if ($orig_w > $orig_h) {
                 $size_w = $orig_w * $height / $orig_h;
                 $size_h = $height;
             } else {
                 $size_h = $orig_h * $width / $orig_w;
                 $size_w = $width;
             }
         }
     }
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             // Imagick::FILTER_BOX faster than FILTER_LANCZOS so use for createTmb
             // resize bench: http://app-mgng.rhcloud.com/9
             // resize sample: http://www.dylanbeattie.net/magick/filters/result.html
             $filter = $destformat === 'png' ? Imagick::FILTER_BOX : Imagick::FILTER_LANCZOS;
             $img->resizeImage($size_w, $size_h, $filter, 1);
             $result = $img->writeImage($path);
             $img->destroy();
             return $result ? $path : false;
             break;
         case 'gd':
             $img = self::gdImageCreate($path, $s['mime']);
             if ($img && false != ($tmp = imagecreatetruecolor($size_w, $size_h))) {
                 self::gdImageBackground($tmp, $this->options['tmbBgColor']);
                 if (!imagecopyresampled($tmp, $img, 0, 0, 0, 0, $size_w, $size_h, $s[0], $s[1])) {
                     return false;
                 }
                 $result = self::gdImage($tmp, $path, $destformat, $s['mime']);
                 imagedestroy($img);
                 imagedestroy($tmp);
                 return $result ? $path : false;
             }
             break;
     }
     return false;
 }
开发者ID:mechiko,项目名称:staff-october,代码行数:76,代码来源:elFinderVolumeDriver.class.php

示例7: createTmb

 /**
  * Create thumnbnail and return it's URL on success
  *
  * @param  string  $path  file path
  * @param  string  $mime  file mime type
  * @return string|false
  * @author Dmitry (dio) Levashov
  **/
 protected function createTmb($path)
 {
     $mime = $this->mimetype($path);
     if (!$this->canCreateTmb($path, $mime)) {
         return false;
     }
     $name = $this->tmbName($path);
     $tmb = $this->tmbPath . DIRECTORY_SEPARATOR . $name;
     // copy image in tmbPath so some drivers does not store files on local fs
     if (($src = $this->_fopen($path, 'rb')) == false || ($trg = @fopen($tmb, 'wb')) == false) {
         return false;
     }
     while (!feof($src)) {
         fwrite($trg, fread($src, 8192));
     }
     $this->_fclose($src, $path);
     fclose($trg);
     if (($s = @getimagesize($tmb)) == false) {
         return false;
     }
     $result = false;
     $tmbSize = $this->tmbSize;
     list($x, $y, $size_w, $size_h) = $this->tmbEffects($s[0], $s[1], $tmbSize, $this->options['tmbCrop']);
     switch ($this->imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($tmb);
             } catch (Exception $e) {
                 return false;
             }
             $img->contrastImage(1);
             if ($this->options['tmbCrop'] == false) {
                 $img1 = new Imagick();
                 $img1->newImage($tmbSize, $tmbSize, new ImagickPixel($this->options['tmbBgColor']));
                 $img1->setImageFormat('png');
                 $img->resizeImage($size_w, $size_h, NULL, true);
                 $img1->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
                 $result = $img1->writeImage($tmb);
             } else {
                 $result = $img->cropThumbnailImage($tmbSize, $tmbSize) && $img->writeImage($tmb);
             }
             break;
         case 'gd':
             if ($s['mime'] == 'image/jpeg') {
                 $img = imagecreatefromjpeg($tmb);
             } elseif ($s['mime'] == 'image/png') {
                 $img = imagecreatefrompng($tmb);
             } elseif ($s['mime'] == 'image/gif') {
                 $img = imagecreatefromgif($tmb);
             } elseif ($s['mime'] == 'image/xbm') {
                 $img = imagecreatefromxbm($tmb);
             }
             if ($img && false != ($tmp = imagecreatetruecolor($tmbSize, $tmbSize))) {
                 if ($this->options['tmbCrop'] == false) {
                     if ($this->options['tmbBgColor'] == 'transparent') {
                         list($r, $g, $b) = array(0, 0, 255);
                     } else {
                         list($r, $g, $b) = sscanf($this->options['tmbBgColor'], "#%02x%02x%02x");
                     }
                     $bgcolor = imagecolorallocate($tmp, $r, $g, $b);
                     if ($this->options['tmbBgColor'] == 'transparent') {
                         $bgcolor = imagecolortransparent($tmp, $bgcolor);
                     }
                     imagefill($tmp, 0, 0, $bgcolor);
                     if (!imagecopyresampled($tmp, $img, $x, $y, 0, 0, $size_w, $size_h, $s[0], $s[1])) {
                         return false;
                     }
                 } else {
                     if (!imagecopyresampled($tmp, $img, 0, 0, $x, $y, $tmbSize, $tmbSize, $size_w, $size_h)) {
                         return false;
                     }
                 }
                 $result = imagepng($tmp, $tmb, 7);
                 imagedestroy($img);
                 imagedestroy($tmp);
             }
             break;
     }
     return $result ? $name : false;
 }
开发者ID:JoeDukes,项目名称:ScheduleIt,代码行数:88,代码来源:elFinderVolumeDriver.class.php

示例8: cropImage_common

<?php

$case = "show_img";
//show_img, save_img
$cropThumbnailImage = true;
$filename = "img/" . $_GET["file"];
if (class_exists("imagick")) {
    $im = new imagick($filename);
    /* create the thumbnail */
    if ($cropThumbnailImage) {
        $im->cropThumbnailImage(80, 80);
    }
    /* Write to a file */
    if ($resizeImage) {
        $im->resizeImage(900, 80, 1, 0.5);
    }
    switch ($case) {
        case "write_img":
            $im->writeImage("img/" . $_GET["file"]);
            break;
        case "show_img":
            header("Content-Type: image/jpg");
            echo $im->getImageBlob();
            break;
    }
} else {
    cropImage_common($filename, 80, 80);
}
function cropImage_common($filename, $width, $height)
{
    // Content type
开发者ID:vihoangson,项目名称:Program_lesson,代码行数:31,代码来源:show_img.php

示例9: resize_imagick

 private function resize_imagick($src, $width, $height, $quality, $preserveExif)
 {
     try {
         $img = new imagick($src);
         if (strtoupper($img->getImageFormat()) === 'JPEG') {
             $img->setImageCompression(imagick::COMPRESSION_JPEG);
             $img->setImageCompressionQuality($quality);
             if (!$preserveExif) {
                 try {
                     $orientation = $img->getImageOrientation();
                 } catch (ImagickException $e) {
                     $orientation = 0;
                 }
                 $img->stripImage();
                 if ($orientation) {
                     $img->setImageOrientation($orientation);
                 }
             }
         }
         $img->resizeImage($width, $height, Imagick::FILTER_LANCZOS, true);
         $result = $img->writeImage($src);
         $img->clear();
         $img->destroy();
         return $result ? true : false;
     } catch (Exception $e) {
         return false;
     }
 }
开发者ID:idea-lab,项目名称:Spectrum,代码行数:28,代码来源:plugin.php

示例10: resizeImg

 /**
  * Resize image
  *
  * @param  string   $path       image file
  * @param  int      $width      new width
  * @param  int      $height     new height
  * @param  bool	    $crop       crop image
  * @param  bool	    $exactfit   fit into given dimensions exactly
  * @param  string   $imgLib     image library
  * @param  string   $bgcolor    image background color
  * @param  string   $destformat image destination format
  * @return string|false
  * @author Dmitry (dio) Levashov, Alexey Sukhotin
  **/
 protected function resizeImg($path, $width, $height, $crop = false, $exactfit = false, $imgLib = 'imagick', $bgcolor = '#0000ff', $destformat = null)
 {
     if (($s = @getimagesize($path)) == false) {
         return false;
     }
     $result = false;
     list($x, $y, $size_w, $size_h) = $this->getResizeCropDimensions($s[0], $s[1], $width, $height, $crop, $exactfit);
     switch ($imgLib) {
         case 'imagick':
             try {
                 $img = new imagick($path);
             } catch (Exception $e) {
                 return false;
             }
             $img->contrastImage(1);
             if ($crop == false) {
                 $img->resizeImage($size_w, $size_h, NULL, true);
                 if ($exactfit == true) {
                     $img1 = new Imagick();
                     $img1->newImage($width, $height, new ImagickPixel($bgcolor));
                     $img1->setImageFormat($destformat != null ? $destformat : $img->getFormat());
                     $img->resizeImage($size_w, $size_h, NULL, true);
                     $img1->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
                     $result = $img1->writeImage($path);
                     return $result ? $path : false;
                 }
             } else {
                 $img->cropImage($width, $height, $x, $y);
             }
             $result = $img->writeImage($path);
             return $result ? $path : false;
             break;
         case 'gd':
             if ($s['mime'] == 'image/jpeg') {
                 $img = imagecreatefromjpeg($path);
             } elseif ($s['mime'] == 'image/png') {
                 $img = imagecreatefrompng($path);
             } elseif ($s['mime'] == 'image/gif') {
                 $img = imagecreatefromgif($path);
             } elseif ($s['mime'] == 'image/xbm') {
                 $img = imagecreatefromxbm($path);
             }
             $init_w = $size_w;
             $init_h = $size_h;
             if ($exactfit == true) {
                 $init_w = $width;
                 $init_h = $height;
             }
             if ($img && false != ($tmp = imagecreatetruecolor($init_w, $init_h))) {
                 if ($crop == false) {
                     if ($bgcolor == 'transparent') {
                         list($r, $g, $b) = array(0, 0, 255);
                     } else {
                         list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
                     }
                     $bgcolor1 = imagecolorallocate($tmp, $r, $g, $b);
                     if ($bgcolor == 'transparent') {
                         $bgcolor1 = imagecolortransparent($tmp, $bgcolor1);
                     }
                     imagefill($tmp, 0, 0, $bgcolor1);
                     if (!imagecopyresampled($tmp, $img, $x, $y, 0, 0, $size_w, $size_h, $s[0], $s[1])) {
                         return false;
                     }
                 } else {
                     if (!imagecopy($tmp, $img, 0, 0, $x, $y, $width, $height)) {
                         return false;
                     }
                 }
                 if ($destformat == 'jpg' || $destformat == null && $s['mime'] == 'image/jpeg') {
                     $result = imagejpeg($tmp, $path, 100);
                 } else {
                     if ($destformat == 'gif' || $destformat == null && $s['mime'] == 'image/gif') {
                         $result = imagegif($tmp, $path, 7);
                     } else {
                         $result = imagepng($tmp, $path, 7);
                     }
                 }
                 imagedestroy($img);
                 imagedestroy($tmp);
                 return $result ? $path : false;
             }
             break;
     }
     return false;
 }
开发者ID:laiello,项目名称:avecms,代码行数:99,代码来源:elFinderVolumeDriver.class.php


注:本文中的imagick::resizeImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。