如何使用imagick扩展名更改图像的dpi [英] how can i change the dpi of an image with the imagick extension

查看:292
本文介绍了如何使用imagick扩展名更改图像的dpi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将所有上传的文件更改为72 dpi. 我正在使用php imagick扩展名.

I need to change all uploaded files to 72 dpi. I'm using the php imagick extension.

这是我尝试过的内容(我使用的图像是300dpi):

heres what i've tried (the image i'm using is 300dpi):

$image = new Imagick();
$image->setResolution(72,72) ;
$image->readImage($img);
$image->resampleImage  (72,72,imagick::FILTER_UNDEFINED,1);
$image->writeImage($target)

这似乎没什么. 图片正在上传,但保持在300dpi

this doesn't seem to anything. the image is uploading, but stays at 300dpi

推荐答案

MatTheCat的答案很明确.您也可以尝试setImageUnits()来确保它使用英寸而不是厘米.

MatTheCat's answer is spot on. You might also try setImageUnits() to ensure it's working with inches and not centimeters.

$image->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$image->setImageResolution(72,72);

仅需更改dpi即可重新采样.

Resampling isn't necessary just to change dpi.

请注意,仅更改dpi不会影响文件大小,而仅适用于重采样和打印.

Note that changing the dpi alone will not affect file size and only applies to resampling and printing.

这篇关于如何使用imagick扩展名更改图像的dpi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆