Jump to content

Resized images larger than original?


a-ok
 Share

Recommended Posts

I'm resizing my images for img srcset using a helper function:

function getSrcsetImages($image, $variations, $sizes) {
	$srcset = array();
	if (empty($variations)) {
		$srcsetSizes = array(100, 200, 300, 400, 500, 640, 750, 828, 1024, 1125, 1242, 1280, 1400, 1500, 1600, 1700, 1800, 1920);
	} else {
		$srcsetSizes = explode(", ", $variations);
	}
	foreach ($srcsetSizes as $s) {
		if ($s <= ceil($image->width())) {
			$srcset[] = $image->width($s)->url() . " {$s}w";
		}
	}
	$srcset = implode(", ", $srcset);
	echo "src=\"{$image->url}\" data-srcset=\"{$srcset}\" sizes=\"{$sizes}\"";
}

<img <?php getSrcsetImages($image, null, "auto"); ?> class="--lazy" />

This works in theory but in my assets folder why are the variations, on average, larger than the original? Feels like I should just use one image at this point?

190412416_Screenshot2019-10-11at20_57_34.thumb.jpg.f6ae822bed7adf70889ee8fe898e8472.jpg

Any thoughts on what I'm doing wrong?

Link to comment
Share on other sites

2 hours ago, dragan said:

Are you using image compression at all?

Are you seriously going to use 18 variations in a live site? Or is this just a test?

Not to my knowledge. I have this in my config.php file:

$config->imageSizerOptions('sharpening', 'none');
$config->imageSizerOptions('quality', 100);
$config->imageSizerOptions('defaultGamma', -1);

And yes just a test ?

Link to comment
Share on other sites

16 hours ago, a-ok said:

$config->imageSizerOptions('quality', 100);

It all depends on how your original image was created. Was it saved at maximum quality? Was it passed through some sort of optimisation process/service (TinyJPG, CompressOrDie, etc) that compressed the image and reduced the filesize? Your PW resizer settings are asking for maximum quality, minimum compression, and therefore you can expect relatively large filesizes. And the PW resizer is not going to produce filesizes as small a specialised optimisation service, particularly one that you customise the settings of per image.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...