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.

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况