class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
Right, I want to be able to resize images easily to a certain total amount of pixels.
Let's say that my "optimal size" is something like 640x480 = 307200 pixels.
All pictures that have the same aspect ratio will be sized to 640x480 or 480x640.
But pictures with other aspects should be resized to have as many pixels (as good as possible).. for example an image that is 720x480 (= 345600 pixels, dvd size) it should be resized down to something like 679x453 = 307587 pixels.
As of now, there is no way to do this. But it is a good idea, and I will try to implement it in a future version. Maybe the next release if I can find enough time.
But just one question: what happens if your original picture has a 1:50 ratio for instance? The algorithm you loosely described in your post will result in a very wide (or high) image. I suppose maybe there should be some boundaries (max ratio, or max width, or max height) so that you don't find yourself with such pictures, unless you really want to.Reply
I'm hacking up something here, I can send it to you when I'm done but it probably won't be too pretty :)
It would make sense to have a value like.. aspect_boundary(value1, value2) that would work together with aspect_crop and aspect_fill. they would be working like image_ratio_fill and image_ratio_crop i guess?Reply
Yes, please send me any code you do, regardless of the quality :)
As for the settings, it looks to me that aspect_crop and aspect_fill won't be needed, since it will size up the picture to a number of pixel, conserving the ratio. But it won't actually have to crop or fill anything since you want to keep the original ratio.
Wouldn't it be more a case for a new setting such as image_ratio_pixels, which would be an integer (the number of pixels)? That setting will resize the picture, conserving ratio, but increasing or reducing the dimensions so that the number of pixels is (approximatively) met.Reply
Let's say that my "optimal size" is something like 640x480 = 307200 pixels.
All pictures that have the same aspect ratio will be sized to 640x480 or 480x640.
But pictures with other aspects should be resized to have as many pixels (as good as possible).. for example an image that is 720x480 (= 345600 pixels, dvd size) it should be resized down to something like 679x453 = 307587 pixels.
Am I making sense?
Can you post an example?
As of now, there is no way to do this. But it is a good idea, and I will try to implement it in a future version. Maybe the next release if I can find enough time.
But just one question: what happens if your original picture has a 1:50 ratio for instance? The algorithm you loosely described in your post will result in a very wide (or high) image. I suppose maybe there should be some boundaries (max ratio, or max width, or max height) so that you don't find yourself with such pictures, unless you really want to.
It would make sense to have a value like.. aspect_boundary(value1, value2) that would work together with aspect_crop and aspect_fill. they would be working like image_ratio_fill and image_ratio_crop i guess?
As for the settings, it looks to me that aspect_crop and aspect_fill won't be needed, since it will size up the picture to a number of pixel, conserving the ratio. But it won't actually have to crop or fill anything since you want to keep the original ratio.
Wouldn't it be more a case for a new setting such as image_ratio_pixels, which would be an integer (the number of pixels)? That setting will resize the picture, conserving ratio, but increasing or reducing the dimensions so that the number of pixels is (approximatively) met.
Actually it should probably be called a "resize to area", right? since the area of a rectangle is height*width.
sqrt does the trick!
Thanks for the contribution.