Jump to content

Where to set image resizing quality and how to re-resize images


Adam Kiss
 Share

Recommended Posts

Hello,

I have, during building the site changed the imagined size of pictures. Now I found myself with sizes I'm okay with, but I need to re-resize all the images again & with higher quality, because I'm unsatisfied with current quality, caused by (besides other things) by multiple resizes I did in my code.

How to do it?

Note: I know that Ryan already posted some linux/mac terminal code to clean-up images (thus forcing them to recreate), but I can't fucking find it.

Link to comment
Share on other sites

Adam, ProcessWire doesn't actually resize your original image, so they should still be in tact. All you have to do is change the resize dimensions and it should be creating the new sizes from the original. But if you want to go in and delete all the extra files for sizes you aren't using anymore, give me a couple days. :) I'm working on an addition to the FieldtypeImage module for that (an image cache clearing module).

  • Like 1
Link to comment
Share on other sites

Yeah, except I really need to change quality, to have the pictures a little less blurry.

And also, I tried a lot of sizes, I want to those resized images gone :) And I know that PW duplicates pictures, doesn;t resize original... that's why I can't just go to e.g. cache/images and delete stuff – because it's in the same dir as originals, so I would have to be extre careful :)

Isn't there some other way, via API maybe?

Link to comment
Share on other sites

Well it's actually easy to identify the resized versions because they always follow a common format of filename.123x456.jpg (or substitute another width/height and image extension). Whereas the originals have the same filename, but without the .123x456.jpg part. So the cache clear will be pretty straightforward to write... it'll just look for any images that have that last part and a corresponding filename without it. Then it'll remove all the versions with the .123x456.jpg in the filename.  But tracking them down requires a regular expression, so it's not something you can do so easily from your OS (unless you are good with unix file commands... I wouldn't know where to start).

So assuming that the full size versions you already have in there are good, then you should be able to resize them to a different dimension. That leaves you with just the extra/unnecessary files you want to delete. Do I have it right?

Link to comment
Share on other sites

This is an excellent idea. This is what PW uses for cleanup when you delete a page. For a site-wide cache clear of images, this may work very well. But on a really large site, it may be slow (or run out of memory) since it'll involve loading all the pages on the site. So for the image cache clear that I'm writing, it's going to most likely just stick with hunting in the file system and confirming that it's a variation based on the existence of the full size image.

Link to comment
Share on other sites

  • 3 years later...

This is an excellent idea. This is what PW uses for cleanup when you delete a page. For a site-wide cache clear of images, this may work very well. But on a really large site, it may be slow (or run out of memory) since it'll involve loading all the pages on the site. So for the image cache clear that I'm writing, it's going to most likely just stick with hunting in the file system and confirming that it's a variation based on the existence of the full size image.

Hey Ryan. I came across this post looking for how to clear image cache. I wonder, did this "image cache clear" module ever come to light?

  • Like 2
Link to comment
Share on other sites

  • 3 weeks later...

I have made a module for you (all). :ph34r:

I have had allready a routine that iterates through all pages and clears all imagevariations. But this only can be safely used if you have not used images in RTE's from the same page. If you have done so, those cannot be identified and gets deleted too. :(

So please double check that you do not use Pageimages in your RTE fields before running this module.

To run it you have to install it, go to its configscreen and check the box to run it. Also there is a second box, always checked by default, that let the script run in testmode. In testmode it doesn't delete the variations but list all found pages and the images count. So, if you really want to delte all ImageVariations sitewide, tipp the box to run the script, untipp the box to run it in testmode and press the submit button.

PageimageRemoveVariations.zip

EDIT: better use this enhanced module version from @tpr, with configuration for excluding imagefields:

enhanced version!

 

Edited by horst
  • Like 8
Link to comment
Share on other sites

This is really great. Functions like it should. If you have time for it, I could suggest a few enhancements for UI:

"Cosmetic"

- it is not clear how to use it, as the module does not create any menu items; maybe a menu item would be preferable

- it is not clear you have to check both boxes to even get a list of images; maybe 1 checkbox (checked by default) will be enough?

- i can imagine the list getting really long, so it would not be usable to see it in the message area at the top (maybe make a list below the submit button)

- it could be more clear to call the "submit" button something like "clear image cashe" or "clear image variations"

"Core"

- in joomla and some of its plugins you could see the list of pages and/or images which would be removed while clearing the cashe and check/unckeck them - could be beneficial for this module and make use of something alike page lister

- it would be great to have an opportunity to clear image variations from the page admin on per-page or (wild dreams) even per-image basis

I am not expecting you to start on this right now, you already "made my day", horst. Thank you! People waited since 2011 for the solution like this, and I got it in just one night. Isn't it a miracle?

P.S. I think this module should make its way to the directory.

Edited by Ivan Gretsky
  • Like 1
Link to comment
Share on other sites

@Ivan: I appreciate your contributions / tipps. :)

But, -

1) the script was hacked together last night in under 30 minutes including testing. It comes from that source (a proof of concept)

2) there is a very big black hole whith this:

The script iterates over imagefields and than over single images, calling getVariations() bzw. removeVariations(). That's all. This leads into that all images used by RTE-Fields on the same page could not be identified as those. So the script simply deletes them too :(

There may be a possibilty to detect some of the embedded images in RTE-fields, those using an HTML <img tag, but there are a lot of known and unknown possibilties how images can be embedded into RTEs. Think of HannaCodes, Markdown, BBCode, other Tools/Modules that store (generic) code into RTE's to later on runtime build a proper URL or img tag from it.

All those get dropped and cannot recreated automatically, like those from imagefields. Also CropImage-fields will lost there individual CropAreas and fall back to automaticlly created ones.

Therefore this is a very pour solution, only offered to some people here who do know about that risc and who are able to handle that right (during development only). (hopefully) :P

As long as there is no solution that can cover the above noted cases, I do not release it elsewhere.

Finally I'm glad that it can be of help in a small use case. :)

  • Like 3
Link to comment
Share on other sites

  • 7 months later...

So please double check that you do not use Pageimages in your RTE fields before running this module.

RemovePageimageVariations is a great tool but unfortunately this limitation makes it hard to use.

How about adding a check to delete only variations where the field name does not have "rte" in it?

// after line 109
// do not process fields having "rte" in name (eg. "images_rte")
if(strpos($field->name, "rte") !== false) {
    continue;
}

I know it is hacky but allows adding fields to pages where images won't be deleted.

Of course I'm open to other solutions too.

Link to comment
Share on other sites

Yep, you can exclude fields on a page. This is not a hacky solution, you can use it as a customized version, or you make the module configurable with at least one Textarea field where you define imagefields to exclude, one per line. This way you can drop it into diferent sites and no need to hack. :)

Link to comment
Share on other sites

I wonder which would be a better solution:

  • include all fields (the way it works now) and provide an exclude list setting
  • exclude all fields by default and add an include list feature
Link to comment
Share on other sites

Here is the updated PageimageRemoveVariations module with the exclude list:

post-3156-0-80867400-1432669887_thumb.pn

PageimageRemoveVariations.zip

I went with exclude list instead of include list to make it backward compatible.

I think making exclude/include feature configurable would unnecessarily overcomplicate things.

I've also added myself to the author field not to blame horst if the excludeList goes fatal :)

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

Hi there,

I've been playing around with the imagesizer.php to change the quality of the images resized. However, to my surprise, if I change the setting "protected $quality = 90;" down to 80 or 70, it doesn't decrease the filesize… Am I doing something wrong?

Thanks

Link to comment
Share on other sites

Are you re-uploading the image or otherwise forcing a regeneration of those thumbnails? Also are you sure you're looking at thumbs and not the original image?

I'm comparing the files in the assets folder. I've deleted the resized file in order to able PW to re-generate one. The filesize is always the same. What's a bit weird is that the filesize ends with xxx.2500x0.jpg. I don't know why it says "0" at the end. I'm using the function "->width(2500)"

Should i rename the original and import it again?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...