douzen1880 2016-07-10 21:20
浏览 186
已采纳

我的php图像服务器使用Imagick在裁剪/缩小后产生更大的png8文件

I'm trying to set up a simple PHP image server to allow me to add just large file for each of my images and then scale and crop them as needed. For my test file I start with a png8 exported via "save for web" from illustrator of size 2400 x 1200, which has a filesize of 21.6KB.

When I use Imagick's cropThumbnailImage function to reduce it to 600 x 600 the resulting file is 62.1KB (three times the size for a substantially smaller image). A 600 x 600 crop of the same image saved from illustrator clocks in at about 8.2KB. I can accept a modest file size increase for the added convenience, but an ~8x increase is just too much.

When saving the file I make sure to force the output to png8 so it doesn't default to a lossless png format, but other than that I'm clueless as to how to resolve it.

Here is my processing code:

//create working image
$image = new Imagick( $this->orig_file );

// Set Compression
$image->setImageCompressionQuality( 9 );

//scale image to height
$image->cropThumbnailImage ( $this->w, $this->h );

// strip extra data
$image->stripImage();

// save file
$image->writeImage( 'png8:'.$this->output_file );

Here are my test files:

Original Full scale image outputted by illustrator.

Cropped 600 x 600 image generated by imagick.

[EDIT: As per Mark's suggestion below I added the following changes]

// replacing cropThumbnailImage with:
$image->resizeImage(0, $this->h, imagick::FILTER_TRIANGLE, 1);

// crop
$start = ($image->getImageWidth() / 2) - ($this->w / 2);
$image->cropimage($this->w, $this->h, $start, 0);

// reduce colors to 20
$image->quantizeImage($this->q, 1, 0, true, false); // using 20 as $this->q

The end result goes from 62.1KB to 50.4KB, better but still over double the size of the fullsized image, and many times larger that the illustrator save for web version at that size.

600x600 image reduced to 20 colors and resized not thumbnailed

  • 写回答

1条回答 默认 最新

  • dopgl80062 2016-07-11 08:11
    关注

    Your original image has 33 colours and weighs in at 22kB.

    If you resize like this (albeit at the command line):

    convert jabba.png -resize 600x600 -strip png8:result.png
    

    the output file will be 6.6kB.

    If you resize like I suggested with -scale:

    convert jabba.png -scale 600x600 -strip png8:result.png
    

    the output file will be 5.0kB.

    If you retain -quality 9 in there, you will end up with > 25kB.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 使用matlab将观测点聚合成多条目标轨迹
  • ¥15 Workbench中材料库无法更新,如何解决?
  • ¥20 如何推断此服务器配置
  • ¥15 关于github的项目怎么在pycharm上面运行
  • ¥15 内存地址视频流转RTMP
  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析