Resizing the image in php for viewing purposes only

后端 未结 15 1739
面向向阳花
面向向阳花 2020-12-14 13:09

Okay, the reason I posted this is because I wasn\'t sure what to search for. I\'ll try to explain it as clearly as I can.

Say, I have an image sized 800x600. The box

15条回答
  •  醉话见心
    2020-12-14 13:40

    I have a shell script in place that does exactly what you need with ImageMagick:

    #!/bin/sh
    SOURCE='/path/to/img'
    FILE='myfile.jpg'
    
    convert $SOURCE/$FILE -thumbnail 150x150^\> -quality 85% \
            -gravity center -extent 150x150 ${SOURCE}150/$FILE
    
    • This resizes to a box covering 150x150 - the ^ after 150x150 is essential!
    • The -thumbnail option strips all meta-information except for color profiles and is very fast.
    • Then it cuts a box with 150x150 from the center (-gravity center -extent 150x150) - exactly what you want.
    • In addition I set -quality 85% which should be plenty while reducing file size a lot.
    • In this example I take the image from an img directory and write the thumbnail with the same filename to a img150 directory right next to it.

    Experiment for best results.

    I had help from:
    http://www.imagemagick.org/Usage/files/
    http://www.imagemagick.org/Usage/resize/
    http://www.imagemagick.org/script/command-line-options.php#thumbnail

提交回复
热议问题