Announcement

#1 2016-01-02 16:15:52

mathias
Member
2011-12-11
10

4K photos without image resize (GD / ImageMagick) on low spec VPS

Hi Piwigo Users,

I wanted to share this post with you to provide you with information how I significantly improved the performance of 4K photos on my low spec VPS (256 MB ram, 1024GB bandwidth, 3 Euros/month).

I am using Piwigo with 3840 x 2160 JPG files compressed with quality setting 80% so that each file is approximately 1MB.

The multiple image size convert (handled by the i.php script) takes a long time on my server to create different sizes of of each photo and also uses hdd space to store the generated images. Even 2s (small thumbnails) images take time to generate as the image library needs to read the entire 1MB file first and then converts it.

I decided that I want to disable the image convert - multiple sizes - completely by changing the image URLs with a regular expression to the source file (instead of i.php) and let the browser do the resize.

I use the smartpocket template for my site but I guess you can use the regular expression below for other templates as well.

In themes/smartpocket/template/thumbnails.tpl I changed ( note adjust jpg to your file extension):

----------------------------------------------

Code:

{if !isset($thumbnail.representative_ext)}
    <a href="{$pwg->derivative_url($picture_derivative_params, $thumbnail.src_image)" data-picture-url="{$thumbnail.URL}" rel="external">
{else}
    <a href="{$thumbnail.URL}" target="_blank" onClick="window.location='{$thumbnail.URL}'">
{/if}
     <img src="{$derivative->get_url()}" {$derivative->get_size_htm()} alt="{$thumbnail.TN_ALT}">
{else}
  <li class="liEmpty">
    <a href="{$pwg->derivative_url($picture_derivative_params, $thumbnail.src_image)" rel="external">
{/if}

--------------------------------------------------
to

Code:

{if !isset($thumbnail.representative_ext)}
    <a href="{$pwg->derivative_url($picture_derivative_params, $thumbnail.src_image)|regex_replace:'/(?:(?:_data\/i\/)|(?:i\.php\?\/))(.*)-..\.jpg/':'$1.jpg'}" data-picture-url="{$thumbnail.URL}" rel="external">
{else}
    <a href="{$thumbnail.URL}" target="_blank" onClick="window.location='{$thumbnail.URL}'">
{/if}
     <img src="{$derivative->get_url()|regex_replace:'/(?:(?:_data\/i\/)|(?:i\.php\?\/))(.*)-..\.jpg/':'$1.jpg'}" {$derivative->get_size_htm()} alt="{$thumbnail.TN_ALT}">
{else}
  <li class="liEmpty">
    <a href="{$pwg->derivative_url($picture_derivative_params, $thumbnail.src_image)|regex_replace:'/(?:(?:_data\/i\/)|(?:i\.php\?\/))(.*)-..\.jpg/':'$1.jpg'}" rel="external">
{/if}

--------------------------------------------------

Changing the template to use the original file uses more bandwith but is faster to load the images (no conversion required) and doesn't use disk space for the multiple size images.

Kind regards,
Mathias




Piwigo version: 2.7.4

Last edited by mathias (2016-06-26 16:22:35)

Offline

 

#2 2016-01-02 16:21:19

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3277

Re: 4K photos without image resize (GD / ImageMagick) on low spec VPS

I really don't think it's a good idea... your visitors will have a tremendous bandwidth usage for no reason.

You still have the possibility to generate the multisize your self and drop them in "_data" directory.

Offline

 

#3 2016-01-02 16:39:05

mathias
Member
2011-12-11
10

Re: 4K photos without image resize (GD / ImageMagick) on low spec VPS

Hi Mistic,

thanks for your reply. I agree with you on your comment that we can generate the multiple sizes locally but I find it more user friendly to perform this task on the server or switch off the feature like I did.

I only share the images with my family and I also got 1TB of bandwidth per month.
This would mean they could view 1 million pictures per month to hit that limit which I think will never happen in a single month.

I prefer the fast loading time of the images now and the fact that I can use the entire disk space for files instead of giving away space for multiple sizes.

I am not saying this is the best solution for everybody as obviously 1MB per file will quickly consume bandwidth on a mobile data connection.

For me its the best settings I have found so far, maybe its worth to build into the source an option to completely disable multiple sizes including medium and use image source files in all templates if the user prefers this.

It would be a trade-off: Image loading speed, performance and space of piwigo for more bandwidth usage.

I have never used Piwigio on better VPS hardware maybe this is why I face these challenges.

Thanks,
Mathias

Last edited by mathias (2016-01-02 22:55:33)

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact