Site logo

Archived topic

Force specific featured image sizes on archives

4 replies · Started by Peter on May 3, 2021

Viewing posts 1–5 of 5

Hi,
I have been reading a lot about this subject on the GP forum pages, and there are a lot of topics submitted on this.
BUT:
I still need some advice on how to force a specific set of featured image sizes on especially archive pages.
I know that this might not be a GP related question, but if you could please offer some advice on this scenario:

  • We have clients that act as editors on their own site.
  • They ALL find it too cumbersome to have to scale the images they want to use in articles (some clients produce a massive amount of articles every month).<br/>They (the clients) don't want to have to open up Photoshop and scale images to a size, that we as their web consultancy have specified.
  • They want a soluion where they can just upload and use any image as a featured image and then the sizing and re-sizing are forced to specific sizes and taken care of by the GP/WP solution we provided to the client.
  • Most of our clients are fully aware and accept that this might in some cases result in grainy and/or pixelated images

Is that possible somehow to do with GP?

Whatever I try to set as values in the GP customizer and in the WP media settings the minute an image is off the sizing convention, it is not displayed properly.

Thank you

P.

correction: In bullet point two it should read:

"They ALL find it too cumbersome to have to scale the FEATURED images they want to use in articles..."

Hi there,

there are a couple of ways to do this.

1. Is to use CSS to force the images to be displayed at fixed height and cropped. If you edit the Customizer > Layout > Blog --> Featured Images > Archives you are able to just set a Height Property - in doing so the system should crop the images to those sizes.

Note: In doing so Browsers will not be able to select the src-set size images - which may or may not affect loading times.

2. Register a new Media Attachment size that has a fixed aspect ratio and crop position - using a PHP Snippet like this:

add_action( 'init', function() {
    add_image_size( 'landscape-crop', 500, 200, array( 'center', 'center' ) ); // 500 width, 200 height, crop, centered
} );

This will add a new media attachment size that can be selected in the Customizer settings mentioned above.
In the example it creates a 500px wide x 200px high image - and the cropping is centred. You would just need to set the dimensions to match an aspect ratio you want.

Note: to apply this to existing images, you would need to run the Regenerate Thumbnails plugin. Be mindful if you have a LOT of images that could be quite a long process as well as adding more files to your database.

The alternative - if the editors don't want to open Photoshop is to have someone setup some Photoshop Batch Actions - for different cropping requirements - then its just a case of drag drop to create a resized file :)

Hi David,

Thank you for your reply and for your time and help!

I'll try it out. :-)

cheers

P.

You're welcome

This archived topic is closed to new replies.