Image upscaling

I’m trying to upscale some images on the fly to use as a page header… so far it doesn’t seem to work at all.

	<?php
		$headerimg = $page->images()->sortBy('sort')->first()->thumb([
			'quality' => 80,
			'width' => 1920,
			'upscale' => true]);
	?>

the image itself is then called in the code by

	<?= $headerimg->url() ?>

But it never enlages the file… what am I doing wrong? Original image is only 300px wide.

Going from 300px up to 1920px will look really bad. Images scale down very well but will look atrocious if you scale up more than about 10%. I would strongly recommend using images closer to the intended size.

resize() wont do it, and I guess that is why thumb() also won’t. If you really must do this, you can get around it with the FocusCrop Plugin which while resize above the source file dimensions.

Upscaling works if you crop:

echo $img->thumb(['width' => 5000, 'crop' => true, 'upscale' => true]);

In your case, you could simple set the image’s width to 100% of the container or use it as background image with the size set to covervia CSS?

1 Like