bootScore — the Bootstrap-based WordPress starter theme — can only be designed via CSS, PHP, and JS programming: If you want to fashion your website, you need to program. That’s the way how bootScore integrates bootstrap perfectly: it leaves the unfinished look to the programming web designers.
Unfinished — for example — is bootScore’s handling of the primary post images (= ‘featured images’): Such an image is explicitly assigned to a post and — on the single page — displayed above the text as it has been uploaded into the media library. bootScore manages this quite well. Usually, there is also a big list in a theme containing the first sentences (excerpts/teasers) of all posts, each supplemented by the respective ‘featured image’. bootScore does that, too. However, here the displayed images are blurred and distorted — although they look perfect in the single view.
I had to think around three corners to understand why this had to be. And around one corner to find the solution:
Solution
- Enter the following code into your
functions.php
:
// crop the medium size images to the defined values exactly
// as it is done for thumbnails
if(false === get_option("medium_crop")) {
add_option("medium_crop", "1");
} else {
update_option("medium_crop", "1");
}
Background
So, what’s the problem:
Ideally — according to the web — primary post images (= ‘Featured Images’) are uploaded in 16:9 format, e.g. in the sizes 1200x628 or 1280x768.1 WordPress already calculates in advance — when uploading — smaller versions.2 So it can serve a request faster: It does not have to deliver the large uploaded images again and again to the browser (transfer time), which renders them down to the desired smaller dimensions (computing time) on the client machine. On the other end, WordPress offers developers the option to ask for and include the most appropriate image file for a designed space.
So if I want to illustrate a list of just article titles, I can have WordPress provide me with the path to the smallest image and prepend it to the entry. If I want to beautify the starting lines of the posts, I can ask WordPress for the paths of the medium-large files and have them placed aside from the article’s beginning.
And here it comes: WordPress calculates the additional image files in advance. For those in the smallest thumbnail format, it crops the files to a square size. For the others, it keeps the aspect ratio by default. So for an original image of size ‘1200x628’ it creates a small preview file of size ‘150x150’ (thumbnail) and a larger preview file of size ‘300 x 157’ (medium). But in the list with the article beginnings, bootScore has provided a square space of — for example — 300 x 300
. Thus, if WordPress has sent the browser the small preview file, the browser upsizes the image from 150x150
to 300x300
, which makes it blurry. If WordPress has sent the medium preview file, the browser converts the image from 300x157
to 300x300
, which distorts it. So, plague or cholera! — even if I had manually squared all primary image files: In this case, the large image above the post in the single view would have been distorted or blurred.
However, I wanted to reprogram or exchange the bootScore templates only in case of an emergency.3 So the only thing left to do was to persuade WordPress itself to square the middle format as well. And for this, I actually only had to modify a parameter via the functions.php
.4
- But even in 4:3 format (1200:800) the problem outlined here would arise. [↩]
- thumbnail: 150x150, medium: <300x<300 und large: <1024x<1024 [↩]
- bootScore offers many variants. [↩]
- which I learned of course from the net: see stackoverflow 3454337 [↩]