Image size / thumbnails

Permalink Browser Info Environment
I'm rebuilding my running club website with the modena theme. What I noticed is that in lot's of blocks you use the original uploaded image directly in the views. For example in the offscreen hero unit, or the masonry blog page list template.

In the file manager I have photo's uploaded in 2560x2560 max. I use those in different places, blog posts, the hero units, headers etc. For lots of places the 2560x2560 version is way too big. The images render in the correct size (css), but the large originals are loaded. Offcourse I can resize the images in the filemanager or before uploading. But it would be easier if the blocks / views just resize them to a more sane size for that block.

In order to accomplish this I overrode some of the views locally and used the c5 basic thumbnailer to resize the images in the view where needed. This is cached in c5, so the initial page load will resize the image and cache the resize version.

As an example in the offscreen hero unit view. The image tag in the view is this:

<img src="<?php if ($heroImage) { ?><?php echo $heroImage->getURL(); ?><?php } ?>" class="animated <?php echo $contentAnimation; ?>" alt="">


Where $heroImage is the file object of the original full-size image.

I replaced that with:

$im = $app->make('helper/image');
$thumb = $im->getThumbnail($heroImage, 1280, 700, true);
$tag = new \HtmlObject\Image();
$tag->src($thumb->src)->width($thumb->width)->height($thumb->height);
$tag->addClass('animated')->addClass($contentAnimation);
echo $tag


This will resize (and crop 3rd argument) the image to 1280x700.

I used a different resolution that in the docs (1425x700). Since this will completely fill a 1440p screen in width, and leave some width in a 4k screen just like the suggested size.

Besides this method there is also the thumbnail options built-in to the file manager. You can also specify new thumbnail types. That way the thumbs will be pre-generated when uploading (or rescanning) the files. Then you can use the pre-generated thumbs in the view as well. I did this approach for the masonry blog. I added a thumbnail type "pagelist_3_col" that will resize and crop to 390x292. Then in the view you can just call the thumbnail type handle:

$type = Type::getByHandle('pagelist_3_col');
$src = $thumbnail->getThumbnailURL($type->getBaseVersion());
$tag = new \HtmlObject\Image();
$tag->src($src);
$tag->addClass('overlay__image overlay__image--skew');
echo $tag;

Type: Discussion
Status: In Progress
riotrick
View Replies:
VidalThemes replied on at Permalink Reply
VidalThemes
Hi There,

Sorry for the delay in getting back to you.

Thanks for taking the time to pass this on, and thank you for the detailed rationale it's super helpful, we will definitely add this to the roadmap and get it into Modena.

Best regards

David

concrete5 Environment Information

# concrete5 Version
Core Version - 8.5.7
Version Installed - 8.5.7
Database Version - 20210623000000

# Database Information
Version: 8.0.28
SQL Mode: NO_ENGINE_SUBSTITUTION

# concrete5 Packages
Free Map (1.1.4), Modena Theme (1.2.1)

# concrete5 Overrides
blocks/page_list/templates/modena_masonry_blog/view.php, blocks/page_list/templates/modena_masonry_blog, blocks/page_list/templates, blocks/page_list, blocks/vidal_themes_offscreen_hero/view.php, blocks/vidal_themes_offscreen_hero

# concrete5 Cache Settings
Block Cache - Off
Overrides Cache - On
Full Page Caching - Off
Full Page Cache Lifetime - Every 6 hours (default setting).

# Server Software
Apache

# Server API
fpm-fcgi

# PHP Version
7.4.29

# PHP Extensions
amqp, apcu, bcmath, bz2, calendar, cgi-fcgi, Core, ctype, curl, date, dom, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, igbinary, imagick, intl, json, libxml, lz4, mbstring, msgpack, mysqli, mysqlnd, OAuth, openssl, pcre, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, phpiredis, posix, pspell, redis, Reflection, session, shmop, SimpleXML, soap, sockets, sodium, SPL, sqlite3, standard, sysvmsg, sysvsem, sysvshm, tokenizer, xdebug, xml, xmlreader, xmlwriter, xsl, yaml, Zend OPcache, zip, zlib

# PHP Settings
max_execution_time - 86400
Default max channels per connection - 256
Default max frame size - 131072
amqp.channel_max - 256
amqp.frame_max - 131072
log_errors_max_len - 1024
max_file_uploads - 100
max_input_nesting_level - 64
max_input_time - 60
max_input_vars - 10000
memory_limit - 2G
post_max_size - 512M
upload_max_filesize - 512M
mbstring.regex_retry_limit - 1000000
mbstring.regex_stack_limit - 100000
mysqli.max_links - Unlimited
mysqli.max_persistent - Unlimited
pcre.backtrack_limit - 1000000
pcre.recursion_limit - 100000
pgsql.max_links - Unlimited
pgsql.max_persistent - Unlimited
redis.pconnect.connection_limit - 0
session.cache_limiter - <i>no value</i>
session.gc_maxlifetime - 7200
soap.wsdl_cache_limit - 5
unserialize_max_depth - 4096
xdebug.max_nesting_level - 256
xdebug.max_stack_frames - -1
xdebug.var_display_max_children - 256
xdebug.var_display_max_data - 16384
xdebug.var_display_max_depth - 128
opcache.max_accelerated_files - 10000
opcache.max_file_size - 0
opcache.max_wasted_percentage - 5

Browser User-Agent String

Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You may not request a refund that is not currently owned by you.