I wonder if there is a way to scale down uploaded media exactly to 50%.
From what I see, with add_image_size
you can only specify a width and a height in pixel.
The idea is to upload high resolution images for Retina displays and then let WordPress generate a custom image size scaled down for standard displays.
The best would be apply this to both the original image as well as all the others custom thumbnail generated.
Thanks for the help.
You can use
image_downsize
filter and to catch when WordPress wants a downscaled image and not original, and actually a size what doesn’t exist.Now you have to determine where you need full size or scaled by 50%.
For example you have
I could not use @nvartolomei solution the way it was. It was not functional but still a good starting point.
Here is my final solution:
I add 3 new
image sizes
by doubling the original 3 sizes.Then I put filter when you call them in PHP in order to replace
with
andheight
by their non retina equivalent (since it’s not always about dividing by 2).image.jpg
width=4800
height=4000
image-600x500.jpg
width=600
height=500
large_retina(600×600) : src=
image-1200x1000.jpg
width=600
height=500
original : src=
image.jpg
width=900
height=750
image-600x500.jpg
width=600
height=500
image.jpg
width=600
height=500
function.php:
Now you can just call your images this way
Important: after adding the 3 new sizes, I regenerated all thumbnails with the regenerate-thumbnails plugin