-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use thumbnail
, if possible
#1
Comments
I thought of a couple more things.
I guess there's a potential race between image processing starting and There's a chapter in the docs about how file open works: http://jcupitt.github.io/libvips/API/current/How-it-opens-files.md.html Which might also help explain Anyway, just suggestions, nice job on the plugin. |
Hey, great to hear from you! Thanks for the suggestions, I'm actually already in progress of adding thumbnail support to the plugin. There's some issues with compatibility as most linux systems come with binaries earlier than 8.5 but this can of course fixed by simple version check so those with a later version get the performance boost 🙂 I agree that some logic can be a bit strange because the plugin must adhere to WordPress image editor rules, but it's a good thing if using thumbnail_buffer instead of thumbnail doesn't have a lot of overhead! I'll check out the effect of disabling the cache! If it cuts down memory use I'll be sure to include it in the next version. |
Thumbs up for VIPS support in WordPress, have been looking for a while. It is not uncommon for clients to upload a 10.000px image for the website to process. I usually handle the job in the hardware manner (more memory, more swap to prevent the server to hang) but we know VIPS could have been solved it right there. |
This took a bit more time than I expected but the latest version now uses Instead of I ran a few quick benchmarks and it seems like using Disabling the cache reduced the peak memory use by 22% without any slowdown in the image processing. Big thanks to @jcupitt for the tips! Here are the benchmarks if anyone is interested: |
Hey, nice! But Try this:
It will also give better quality for vector formats like SVG or PDF since it can directly render to the correct size, rather than rendering at the wrong size and then resizing. |
I'm using 20 images from Unsplash which are about 3000-5000 pixels on the larger side. You can see from the benchmarks that comparing vips thumbnail file which uses It might also be that I'm using the library in some sort of wrong way? Or maybe I'm going to run a few more tests to see if I can see a performance boost with It would be possible to modify the logic so that |
It should be really dramatic. Here's a 6k x 4k image:
A 4x speedup. I would do rotate and crop after thumbnail, so you are rotating and cropping a much smaller image. |
Hi @jcupitt, I'm using the latest version of this plugin that has switched to thumbnail instead of resize as per your suggestion. Except that now I'm getting errors on some resizes (extract_area: bad extract area) that are not happening with resize. Do you have any idea why? Thanks 👍 |
Hi @chatelp, post an example that fails and I'll have a look. |
Thanks @jcupitt ! It happens when trying to get a 650x433px thumbnail of the attached image. This is a custom thumbnail size registered in my WP install: add_image_size('custome-thumb', 650, 9999); The _resize function of this plugin is called for each thumbnail size but it fails only on this particular one. More precisely, it fails with the extract_area: bad extract area error at the crop stage that happens in this function after the call to thumbnail_image has been made first. See attached debug session capture bellow. If I replace the call to thumbnail_image to a call to resize, then crop doesn't fail. |
I think your PHP is not quite right -- you are calculating I would change it to always calculate scale in the same manner. |
I see, thanks so much for looking into it, but I'm afraid it's not my PHP code, and that's the problem. I'm just using the vips plugin as-is... for now. So, you are suggesting that I change the code pertaining to scale computation in the _resize method, right? Also, could you explain why is there the need to do a crop following a resize (or thumbnail_image), even when the crop parameter of the _resize function is set to false. I'm sure I'm missing something since I'm no vips expert... nor php expert for that matter :) |
It looks like a minor bug in Sure, you could probably skip the crop in that case, though I think there wouldn't be a performance win. |
I just checked for the other thumbnails that are working, and the scale value is never the same, even for the images where the crop is working... doesn't that exclude the scale value discrepancy as the source of the extract_area: bad extract area error ? @joppuyo are you still working on this? |
Yes, the rounding will only fail for some images. |
Hello! I'm the libvips maintainer. This is very cool!
I had a couple of suggestions after looking through the code that could improve performance and drop memory use.
Use
thumbnail
, if you canI would use
thumbnail
, if possible. It's much, much quicker thannewFromBuffer
andresize
, especially for large reductions on JPG images, and will give higher quality results too, since it will automatically premultiply PNG alpha for you.For example, I think this is roughly what you are doing at the moment:
If I run this on my laptop with a 6k x 4k JPG image, I see:
ie. 135MB of memory, 19s of CPU. If I change it to be:
I see:
So 50MB of memory, under 5s of CPU.
You are cropping before resize, which you can't do with thumbnail. I would use thumbnail anyway, and crop afterwards using scaled down coordinates.
Disable caching
By default, libvips will cache the last 1,000 operations or so. This is usually great for performance, but you are not going to be repeatedly operating on the same image, so it is likely to bloat memory for no gain.
I would add:
To your startup code.
If I remove that line from
try275.php
(the non-thumbnail version above) I see:An extra 90MB of memory used for no speedup.
The text was updated successfully, but these errors were encountered: