Jump to content

Recommended Posts

Posted

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?

Posted

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?

Posted
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 ?

Posted

Anyone? Am I wrong in thinking that the variations would be smaller in filesize? The original is 2000px wide so there’s no upscale.

Posted
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.

Posted

Thanks, @Robin S

The original is saved at JPEG quality 8 in Photoshop. Anything less than 100 in PW, in my experience, messes with the colours so always have to keep it at 100.

 

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
  • Recently Browsing   0 members

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