GD image resize (w/ CI) with huge (6000+ wide) images - codeigniter

I have an application that resizes uploaded images, using the Codeigniter image manipulation class and GD.
However, the client needs to be able to resize super-large images, 6000px or higher. I have memory issues when this occurs.
My question is in two parts- is there a way to calculate how much memory is required, via the dimensions of the image?
Is there a less memory intensive option for resizing these images, which appear to go over 250MB for each action.
Thanks.

GD always works on the uncompressed image; this is where the memory is used. You can estimate the memory consumption as shown in this question. For more information, see also here or here.

Related

Reducing .jpeg PFFiles stored on Parse.com

I have an app running on parse.com backend, with users that creates profiles.
The format is jpeg and the resolution is 640X640.
I've noticed that some photos weights 150KB and other can reach to 500KB.
I want to optimize and reduce the images size without hurting image quality as much via image compression.
I've looked at
https://parse.com/docs/cloudcode/guide#cloud-code-modules
And it seems that the Image module only have crop and resize features. no compression.
How can i reduce the size of the stored jpeg without changing the reference from the object?
Sure i will need a background job... I just need help in figuring how to do it, and any things i need to worry about as the app is live with growing amount of users.
Thanks!

Original size of image - performance relevant in createjs

When loading images via Bitmap() into the stage/container is it relevant regarding the performance once they are loaded and scaled how big the original images were ?
Say I have some images of 800x800 but in the canvas they are only used at a maxiumum size of 400x400. Would it be better to initially onnly make them 400x400?
Yes, the images will become smaller in size, and that is a benefit for your bandwith and performance. Ofcourse the Canvas won't need to scale down the image anymore so the image will be more sharper. Nothing but benefits.

Do we really need separate thumbnail images?

I understand the use of thumbnail in network applications but assuming all the image are in the application itself (photo application), in this case do we still need thumbnail images for performance reasons or is it just fine for the device to resize the actual image on run time?
Since the question is too opinion based I am going to ask more quantitively.
The images are 500x500, about 200-300kb size jpg.
There will be about 200 images.
It is targeted for iphone4 and higher, so that would be the minimum hardware specs users will have.
The maximum memory used should not pass 20% of the devices capacity.
Will the application in this case need separate thumbnail images?
It depends on your application. Just test performance and memory usage on device.
If you show a lot of images and/or they change very quickly (like when you are scrolling UITableView with a lot of images) you will probably have to use thumbnails.
UPDATE:
When image is shown it takes width * height * 3 (width * height * 4 for images with ALPHA channel) bytes of memory. 10 photos 2592 x 1936 stored in memory will require 200Mb of RAM. It is too much. You definitely have to use thumbnails.
Your question is a bit lacking on detail but I assume you're asking if, for say a photo album app, can you just throw around full size UIImages and let a UIImageView resize them to fit on the screen, or do you need to resize?
You absolutely need to resize.
An image taken by an iPhone camera will be several megabytes in compressed file size, more in actual bytes used to represent pixels. The dimensions of the image will be far greater than the screen dimensions of the device. The memory use is very high, particularly if you're thinking of showing multiple "thumbnails". It's not so much a CPU issue (once the image has been rendered it doesn't need re-rendering) but a memory one, and you're severely memory constrained on a mobile device.
Each doubling in size of an image (e.g. from a 100x100 to a 200x200) represents a four-fold increase in the memory needed to hold it.

What is the best way to dynamically resize images?

The problem:
We have large product images we want thumbnails of at various size but don't want to be stuck batch processing the images in Photoshop. We want a dynamic way or resizing images, that wont add an extra load time while the images is processing on the backend.
Amazon does this some how with their ecommerce solution. When you upload an image it resizes the image in square format and then gives you every size imagineable. ex 150x150, 149x149, etc. Starting at the largest size of the image, so if you upload a 1024x900 image it will resize it to 1023x899, 1023x1203 (add in white space where needed), then resize every pixel until it gets to 1x1px. The some how stores all the images to the server (if it even does that)
"there's got to be a better way"
Any suggestions on the best way to handle image resize on the fly?
Dynamic image processing can be incredibly fast, and it's a much better solution than generating every possible combination of sizes for an uploaded image.
The open-source ImageResizing.Net library allows dynamic crop/zoom and resizing, and with the WIC plugin can often have round-trip times of less than 20ms. That's hard to beat. It also offers disk caching and Amazon CloudFront & S3 support if you want to scale with the big folks. It's used by 20K-60K websites, and some servers host upwards of 20TB of images.
I'm pretty sure Amazon uses cached dynamic image resizing for their eCommerce solution. Pre-generating image versions is a very 2001-era solution.
[full disclosure: I'm the author.]

Windows Phone 7 memory management

I'd like to know if there are any specific strategies for handling memory, especially with respect to image caching on the Windows Phone. I have a very graphics intensive silverlight App which needs to keep it graphics that it retrieves from the internet and it needs to be able to freely roam about - but the memory requirement becomes quite huge after using the app for a couple of minutes.
I have tried setting the image's UriSource to null but I need to maintain the image backgrounds when I come back to the page. I'm at a loss because there isn't much information on the internet. The inbuilt profiling showed me "Texture Memory Dominant" and asked me to Analyze Heap Memory to resolve the issue, but I'm still clueless about these.
Any pointers to move forward?
My answer will be general - similarly to your question. I presume that you know for sure that the problem is in images. (Because a simple ListBox with a few hundred text items can cost you many MB.)
If you search the web you'll find plenty of links such as this one. But a general analysis is easy to do.
Take an image of the WP7 screen size, i.e. 480x800. 32-bit bitmap (I suppose this is what WP7 uses when the image is opened) takes roughly 1.5 MB (a simple multiplication).
The same jpg file can have 10x smaller size (for high quality compression) or even less.
Now what's done behind the scenes when you use the construction
<image source="http://..."/>.
(In the absence of any information from you, this is what I suppose you use.)
WP7 downloads the image and adds it to the cache. The cache apparently traces the use of the Uri pointing to the image.
As next the image gets opened, i.e. converted to a bitmap of native image size. Image gets downsampled in this process if it would exceed max. WP7 texture size.
You can customize the bitmap size as described here. If you care of quality, then you should use downscale factor 2, 4, or 8. In case of jpeg these factors represent by far the fastest option. (Well, I have no idea if you know the image resolution before the image gets loaded into the Image control. It is not too difficult to get this info from a jpg file, but right now I have no idea how it can be easily done on WP7.)
The bitmap gets freed if (my speculation) if the control's source is set to null. The downloaded image is purged from the cache when Uri is set to null. (This is reported on the web plenty times.)
If you take all this info, it should be possible to (kind of) control your use of the image cache. You can roughly estimate the image size and can decide which images remain in the cache. Maybe it will need some tricks such as storing Uri objects in you own structures and releasing them as needed. I am not saying this is easy to do, but it is certainly possible.

Resources