doucao1066 2015-05-29 05:00
浏览 110

PHP Imagick:如何在不扩展的情况下调整大小?

I am using PHP Imagick to manipulate images.

I have two use cases: "resize" and "crop".

In the "resize", if the original image's dimensions are less than the given width and the height, I do not want Imagick to scale it up and instead want it to simply return the original size.

However, as the PHP documentation says, the behavior of Imagick has been changed from version 3 (I am using version 6+) that it would always scale up the image.

Note: The behavior of the parameter bestfit changed in Imagick 3.0.0. Before this version given dimensions 400x400 an image of dimensions 200x150 would be left untouched. In Imagick 3.0.0 and later the image would be scaled up to size 400x300 as this is the "best fit" for the given dimensions. If bestfit parameter is used both width and height must be given.

So, in my case, for given dimensions 400x400, an image of dimensions 200x150 should return an image of 200x150 not 400x300. For given dimensions 100x100 an image of dimensions 200x150 should return an image of 100x75 (that is scaling down should happen).

I tried thumbnailImage(), resizeImage() and scaleImage() without any luck. If I set bestfit to false it does the cropping, which is not what I want with resize.

Is there any way to get this done with Imagick?

  • 写回答

2条回答 默认 最新

  • dongzhan8620 2015-05-29 10:08
    关注

    Use this command:

    convert input.img -resize 400x400\> output.img
    

    Note the specific way of giving the wanted dimension with the appended \> modifier: it tells the conversion process to only resize images that are larger than 400x400 pixels. Images which are smaller stay un-touched.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大