【问题标题】:PHP GD or Imagick class Image Magick ConversionPHP GD 或 Imagick 类 Image Magick 转换
【发布时间】:2014-01-30 02:59:53
【问题描述】:

我需要将一些命令行 imagick 代码转换为 php 类。我不能在我们的生产机器上运行命令行脚本,所以我需要能够使用这些类,不幸的是没有关于两者之间转换的文档。

有谁知道我如何使用 imagick 类做到这一点?

$color_mask ="convert -size $dimensions xc:#$color -fill white";

/* create the silver mask */
$silver_mask ="convert -size $dimensions xc:#e6e7e8 -fill white";

/* resize the image to the $larger_dim before cropping it to the dimensions to get that "zoomed in" effect */
$thumb = "convert images/$im -thumbnail $larger_dim^ ". 
" -gravity center -extent $dimensions PNG:-";

/* screen the resized thumbnail and the color mask */
$masked = "convert $thumb $color_mask -compose Screen -gravity center -composite PNG:-";

/* multiply the masked thumb with the silver mask */
$final = "convert $masked $silver_mask -compose Multiply -gravity center -composite PNG:-"; 

/* Output the image*/
header("Content-Type: image/png");
passthru($final, $retval);

我也很乐意在 GD 中做同样的事情,我只是在 GD 中遇到了问题。

TIA

【问题讨论】:

    标签: imagemagick gd image-manipulation imagick imagemagick-convert


    【解决方案1】:

    好的,这需要花费很多时间才能弄清楚,因为 php.net 上的文档不是很好,并且没有任何地方可以解释 ImageMagick 命令行和 Imagick php 类中的函数之间的等效函数。

    这是我执行上述操作的函数:

    public static function getColorImg($img, $color, $filename) {
    
    if (class_exists('Imagick')) {
    
      // Create the blue overlay
      $blue = new Imagick();
    
      // Create a plain colour image in the selected color
      $blue->newImage($dimensions['width'], $dimensions['height'], new ImagickPixel($color));
      $blue->setImageFormat('png');
    
      // Create the plain grey image
      $grey  = new Imagick();
      $grey->newImage($dimensions['width'], $dimensions['height'], new ImagickPixel($silver));
      $grey->setImageFormat('png');
    
      // Now grab the actual image and change it's size to the larger image
      $image = new Imagick($img);
      $image->setImageFormat('png');
      $image->thumbnailImage($larger_dim['width'], $larger_dim['height'], TRUE);
      // now zoom it in
      $image->cropThumbnailImage($dimensions['width'], $dimensions['height']);
      // Screen takes multiple commands in the php class. Negate the two images
      $image->negateImage(false);
      $blue->negateImage(false);
      // Then multipy them.
      $image->compositeImage($blue, imagick::COMPOSITE_MULTIPLY, 0, 0);
      // Re nagate the image so that it looks back to normal.
      $image->negateImage(false);
      // Now multiply it with the silver image
      $image->compositeImage($grey, imagick::COMPOSITE_MULTIPLY, 0, 0);
      // Write out the file as original file name with the prefix
      if ($image->writeImage($filename)) {
        $return = $filename;
      }
      else {
        $return = FALSE;
      }
    }
    else {
      $return = FALSE;
    }
    
    return $return;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-10-16
      • 2011-03-08
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多