I got a Carrierwave uploader and process images like this:
version :thumbnail do
process :resize_to_model
process :quality => 90
end
def resize_to_model
thumbs_size = model.thumbnail_size
resize_to_fill thumbs_size[:width], thumbs_size[:height]
end
However, after processing an image which was 1024x724px and is 214x151px afterwards the file size only went down from 2,1mb to 1,8mb. I think 1,8mb really is a lot for that size. Can I do something about that? Even with 90% quality the image should be like maybe 100kb or not?
Before someone asks, the rest works perfect. No errors, the size in px is right and everything else is also fine.
Edit: I forgot to mention I Use rmagick(resize_to_fill). Is that a reason maybe?
The difference between 100% and 90% quality is so small and the storage space savings is negligible. If you are truly just using this version as a thumbnail you should look at using a much lower quality, say 60% or 40%.
If you are concerned about making sure the quality is still "good enough" then you could also look at different compression techniques. The process used to provide #2x images for Retina displays can be used in this instance. A great resource is available in the Filament Group's article Compressive Images.
The tl;dr version is basically, use the original (or near original) size of the image but drastically reduce the image quality (to 0-20%). Then, when using the reduced quality image be sure to provide width and height attributes in the <img> element to resize it down to the thumbnail size. Because the image will be scaled down you will not see the reduction in quality of the "thumbnail" image.
Related
in our website we are retrieving data from an API, which does not pull images bigger than 100 × 75 pixels, then we show them listed. example We need to double up this size to match with our design.
Is there any Gem that does this, without loosing quality and not impacting performance?
There is no way to upscale an image without losing quality - you're basically asking an algorithm to fill in image data that simply does not exist in the file in the first place.
However, depending on the rate of the scaling and the images themselves, you could have acceptable results.
Since you want to do this effectively and there is no benefit of doing the resizing on the server anyway, I'd advise simply using CSS to achieve this on the client side - just set the desired width/height attributes for the specific img elements.
If you really want to do this on the server (e.g. if you need to save the resulting images), one option would be to use the Paperclip gem's image processing capabilities.
At the moment I am downloading images remotely using a UIImageView category. While the image is downloading I use a placeholder image that is stored in an xcassets folder.
Is it worth having multiple placeholder images for different sizes: small, medium, and large? Or is it worth having 1 placeholder image and using it throughout the application?
Does the size of a placeholder image affect performance?
Well, you should have #2x and #3x version of the images, as it will mean less work by the CPU to scale up / down the image on different devices. Also, there is technically work done by the CPU to scale an image up or down. However, Apple's graphics processor is pretty efficient at scaling images.
So the technical answer is "Yes, it does affect performance", but in reality it is probably not a big enough difference for you to notice.
Now, if you have built a poorly written app that displays hundreds of these placeholders in a UIScrollView instead of some form of a UICollectionView (which only displays what is on screen, or about to be on screen), you will notice that the slight performance difference for all those images adds up to a large performance difference.
I have an image that is used in multiple places within my IOS app at various sizes. Should I be using one large image in conjunction with UIViewContentModeScaleAspectFit to scale it (currently this approach seems to cause distortion on the smaller images despite being scaled to proportionate sizes) or should I have multiple versions of the image at different sizes.
It seems a little extreme to have so many copies of one image e.g. my_image_ipad, my_image_small, my_image_large, my_image_medium.
In general it depends on what it takes to get the look and quality you want. Some images will scale from a large image to a small image with little or no visual loss in quality. Others, as you've found, scale poorly, especially at extreme scales. You're really going to have to just try various solutions and see what works. One way you can almost always cut down on application size is to remove the non-#2x artwork and ship with just the #2x.
It is better to use one image, because it will make your app "lighter", but this may cause your code to become bigger.
Well, i wonder, what compression procession processes they are using..
I uploaded a test image of 2.3mb and suddenly downloaded it
It was only only 92 kbs, what the heck, only 92 kb's
and the thumbnail was only 11 kbs..
How this all is done and what algorithms are utilized.. how do i do it..
If I had to guess, the file size decrease is probably due primarily to just old-fashioned downsampling. Images on facebook are sized to be viewed on part of a screen, but not much larger.
For instance, I uploaded a picture that was 3456x2304 (3.2MB) which is 7,962,624 pixels. This was downsized by facebook to 960x602 (85kB) which is only 577,920 pixels. That only about 1/14th the total number of pixels.
This probably explains the majority of the difference, but it also looks like they are using the sRGB color profile, which can reduce file sizes.
One other possibility is that most JPEG encoders have a quality setting. They may be using a lower quality setting than that of the original.
I'm using attachment_fu and RMagick to upload/resize images on a rails app. Currently I use the local file system as the storage but I have a plan to use AWS S3 for the job. Anyway I am quite interested to know what other peoples' experiences on using S3 and also I have a one big question for you. In my app when a user uploads an image I resize this image to 5 different sizes and store them along with the original images. (altogether 6 images) based on thumbnail sizes provied in the model:
:thumbnails => {
"thumb" => "120x80",
"extra_small"=>"480x320",
"small"=>"640x480",
"medium" => "800x533",
"large"=>"2738x1825",
"extra_large" => "3464x2309"
Finally I get:
image_foo.jpg (Original Image)
image_foo_thumb.jpg
image_foo_extra_small.jpg
image_foo_small.jpg
image_foo_medium.jpg
image_foo_large.jpg
image_foo_extra_large.jpg
The reason why I re-size these images is I need the actual sizes of each image to be stored in the database. But actually even I specified the sizes for thumbnails I don't get the exact sizes. Anyway its OK, as the size is calculated based on the aspect ratio.
But I really don't like to waste the space on the server if I can calculate the thumbnails sizes without saving them to the file system. In other words, I only need to store the original file not the thumbnails, but still I need to get the sizes of the thumbnails. Is it possible to get the actual thumbnail sizes without creating them in RMagick?
Space on S3 is relatively cheap. So I wouldn't worry too much.
However, you could consider converting the images to fewer sizes. You could leave small and extra-small out and use the width and height attributes of the HTML img tag. However, that will make your side load slower and cause more traffic.
I guess what you are really looking for is a solution that converts the files on the fly when they are requested right? I am not sure if there is a solution for that off the shelf. However, this would be a major performance suck.
So my recommendation is to just stick with all the different sizes and pay a few cent more to amazon. This will yield best performance and will be easiest to maintain. You don't have to worry about scaling and the fact that storage is getting cheaper and cheaper works for this solution.