Resizing from 4764px to 960px with php gd or imagemagick creates image of similiar size in KBs (970kb vs 802kb)

352 views Asked by At

I am trying to resize an 4764 × 2680 pixels image to a 960px width image preserving it's aspect ratio. When doing this operation directly with Imagemagick command line tools, the output image would be around 75kb, but in my attempts of resizing programmatically in my Laravel/php app, the output image size is more than 800kb! Almost the same size of the original image with 4x + resolution.

I am not sure if i am missing something, but i don't understand how the output image is so big in KBs. I am using the intervention/image package and tried resizing with both available drivers: gd and imagick, but the output is the almost the same.

public function resize($image)
    {
        $img = Image::make($image);
        $img->resize(960, null, function ($constraint) {
            $constraint->aspectRatio();
        });
        $img = $img->save();

        return $img;
    }

Imagemagick script that creates images of 75kb:

#!/usr/bin/env bash
# Purpose: batch image resizer
# Source: https://guides.wp-bullet.com
# Author: Mike

# absolute path to image folder
FOLDER="aws_images_redux"

# max height
HEIGHT=960

# max width
WIDTH=960


#resize png or jpg to either height or width, keeps proportions using imagemagick
#find ${FOLDER} -iname '*.jpg' -o -iname '*.png' -exec convert \{} -verbose -resize $WIDTHx$HEIGHT\> \{} \;
find ${FOLDER} -iname '*.jpg' -exec convert \{} -verbose -resize $WIDTHx$HEIGHT\> \{} \;
find ${FOLDER} -iname '*.png' -exec convert \{} -verbose -resize $WIDTHx$HEIGHT\> \{} \;

#resize png to either height or width, keeps proportions using imagemagick
#find ${FOLDER} -iname '*.png' -exec convert \{} -verbose -resize $WIDTHx$HEIGHT\> \{} \;

#resize jpg only to either height or width, keeps proportions using imagemagick
#find ${FOLDER} -iname '*.jpg' -exec convert \{} -verbose -resize $WIDTHx$HEIGHT\> \{} \;

# alternative
#mogrify -path ${FOLDER} -resize ${WIDTH}x${HEIGHT}% *.png -verbose
1

There are 1 answers

7
KIKO Software On

In the documentation you see that save() has several options:

quality (optional)

Define optionally the quality of the image. It is normalized for all file types to a range from 0 (poor quality, small file) to 100 (best quality, big file). Quality is only applied if you're encoding JPG format since PNG compression is lossless and does not affect image quality. The default value is 90.

You need to lower the value.