Jump to content
sambadave

Image quality

Recommended Posts

Hi folks

I recently put a site live and in the last stages of the project decided to do some image optimisation.

$options = array(
   'quality' => 70,
   'upscaling' => false
);
$pageImageLargeDesktop = $pageImage->size(960,720,$options)->url;

The thing I love about ProcessWire is that you can change the size here and the new images will be generated across all pages. It's such a time saver. However after adding in $options parameters I expected the quality of the images to reduce on a page refresh, howeever the quality settings only seem to be applied during upload. This meant I had to re-upload all my images again into ProcessWire for the changes in quality to appear.

Is there a way of getting round this? It wasn't a massive problem for this particular site but I'm thinking more along the lines of a larger site with hundreds or thousands of images. You just couldn't go back in and re-upload every image unless you had a lot of time on your hands.

Am I missing a trick? Thanks in advance for any help.

Share this post


Link to post
Share on other sites

Hi sambadave,

as far as I know you don't have to upload the file again. You could go into the files folder and delete only the generated versions of the images.

For example if there is an image "image.jpg" and it has generated versions like "image-600x400.jpg" and so on, you can search all images with "-600x400" delete them and after reloading the site, ProcessWire generates new versions of this image.

You can try it out, but be carefull not to delete the original. Maybe make a backup before and be aware, that generating a lot of images could lead to a timeout when reloading the page, so you have to reload the page several times.

Regards, Andreas

  • Like 1

Share this post


Link to post
Share on other sites

Hi,

I don't have great knowledge of the processwire core, but I think that the following lines in wire/core/Pageimage.php are responsible:

$basename = basename($this->basename(), "." . $this->ext());
...
$basename .= '.' . $width . 'x' . $height . $crop . $suffixStr . "." . $this->ext();
$filenameFinal = $this->pagefiles->path() . $basename;
$exists = file_exists($filenameFinal);

if(!$exists || $options['forceNew']) {
  // Generate and save
...

That means, that indeed the image options are not a dependency for the image file generation.

One can argue about that, but I think that they should be.

Share this post


Link to post
Share on other sites

Hi guys

Thanks Andreas – Good to know I can do that. I'm just a little concerned for larger sites as going through all the image folders to delete certain images could take ages and might involve an element of risk if I was to delete the original image by mistake. Unless there is a way to do this with code?

tsdtsdtsd – I wonder if there could be a way to toggle this setting through the admin to allow options to be taken into account.

It's not a biggie now I know but it would be a shame to have a huge site and have to go through all the images manually. ProcessWire is still awesome though!

Share this post


Link to post
Share on other sites

It's always as a project gets big you'll have to take care. No matter what CMS.

In case of images:

a.  you can now in 2.6 delete variations for a image right in the backend. But that doesn't work for batch processing a whole site's images.

b. you can write a script to delete all variations through API, but that as soon as there's 1000's of pages involved you have to take care of memory, script time etc. Bit this if you own ListerPro (which I recommend all PW users should buy anyway) you can use and build an custom action that batches all your pages (or the ones you filtered) to remove variations. It's built with scalability in mind so it scales for millions of pages (just would take a very long time). 

c. you can also use the API when using $page->image->removeVariations() to delete and force new generation of variations. Then use a template var to toggle that globally in your template. Usually a custom $config var would be best as it allows also modules to read it. This works fine when building a site and you want to experiment to get the best options. Maybe not always suited but something like:

$config->forceNewVariation = true;

The always use a code like this where you generate thumbs or sizes.

$img = $page->image;
if($config->forceNewVariations) $img->removeVariations();
$img = $img->size(100, 100, $options);

Of course this doesn't work well if you're live and have 1000 of pages. As you'd have to view all pages again to trigger new creation WHILE the setting is true.

Just a few ideas.

  • Like 4

Share this post


Link to post
Share on other sites

Maybe there's some new settings in core that would handle that if the setting quality changes it will force a new generation (which would be desired anyway) 

Maybe Horst knows as he worked on that one. I think the new naming convention includes quality, which would make that work.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Soma for the detailed answer. Really appreciate everyone's help here.

It'll take me a while to get my head around all the feedback but I'll see how I get on within a safe testing environment first.

Thanks again :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Mithlesh
      Changing it to null
    • By Mithlesh
      Hi, I have one URL - writerrelocations.com/contact-now/

      I have one issue where my header Image is appearing again after the contact form, for your reference:



      I have checked my processwire template section where have not added any Image field besides Header Image, attaching the same for the reference:




      PLEASE help me to get rid of the image below contact form

      Waiting for the swift response!

      Thanks
       
    • By tonicastillo
      Hi. Can I ask why this happens?
      When I upload a jpg, the meta keywords and description of the file loses the accents and spanish symbols of the words.
      Original image on the left, and the image generated by PW on resize on the right.

      This happens on resize. The uploaded file is ok.
      How can I control which meta keep in the photo?
      Thanks a lot (and sorry for my English)...
    • By nabo
      Hello
      I'm working on a project that use PW as backend CMS. PW serves formatted data of each page but the engine simply generates json from pagearray.
      I would like to set one or more variations on images, so I think it would be useful if there were a field to set possible variations... even with overrides!
×
×
  • Create New...