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. bootScore integrates Bootstrap technically and leaves the visible details to the programming web designers. And by default, it delivers sometimes blurred featured images. Is it an unavoidable task to fix that afterward?
One example of that challenge is bootScore’s handling of the primary post images (= ‘featured images’). By default, the web designer explicitly assigns a picture to a post. The browser displays this picture above the text of a page as it has been uploaded into the media library. bootScore manages this quite well. Usually, a theme offers also a preview list of all posts. In this list, each excerpt of a post is supplemented by the respective ‘featured image’. bootScore organizes that, too. However, the displaying browser blurs the featured images in the post preview — although they look perfect in the post view.
I had to think around three corners to understand why this happened. 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’) shall have a 16:9 ratio, 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 allows the web designer to ask for and include the most appropriate image file for a 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. The browser distorts or blurs the large image above the post. Either in the preview of the post or in the post itself.
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
And how does this …
… support our migration to bootScore? Well, once started with improving the image handling, a web designer will also notice the blurred ‘featured images’ of bootScore. She will try and refine solutions. And she may also tackle them with new HTML‑5 techniques. Because with that, a fancier image strategy combined with an integrated license fulfillment process and its own logo will really make sense. However, pictures bring colors to reading. So they should be integrated into a customized color concept. This post also contributes something to this topic.
- 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 [↩]