Facebook image processing technique - image-processing

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.

Related

jpg or png for user profile pictures?

My app requires that each user has a profile picture of around 140*140px. Right now I am using jpgs, I am wondering if performance wise it will be better to use pngs. I read pngs are good for small UI elements and images, jpg for large images with detail such as photos. Obviously my profile pics are photos but they are small. Would it make much difference switching to png? Thanks
JPEG is best for small file sizes of photos, even for low resolutions.
PNG makes sense when there are many pixels of the exact same color next to each other. This is not the case with photos.
These should be helpful for you.
When to use PNG or JPG in iPhone development?
PNG vs. GIF vs. JPEG vs. SVG - When best to use?
Apple optimizes PNG images that are included in your iPhone app bundle. In fact, the iPhone uses a special encoding in which the color bytes are optimized for the hardware. XCode handles this special encoding for you when you build your project. So, you do see additional benefits to using PNG's on an iPhone other than their size consideration. For this reason it is definitely recommended to use PNG's for any images that appear as part of the interface (in a table view, labels, etc).
As for displaying a full screen image such as a photograph you may still reap benefits with PNG's since they are non-lossy and the visual quality should be better than a JPG not to mention resource usage with decoding the image. You may need to decrease the quality of your JPG's in order to see a real benefit in file size but then you are displaying non-optimal images.
File size is certainly a factor but there are other considerations at play as well when choosing an image format.

Reducing iOS App file size

I have made a very simple iPhone app with Xcode 6.1 and swift. I am really new to ios developing and ran into an app which in the end is 134 mb! of course this is not acceptable.
I have background images for all screen sizes which add up to 20 mb. and thats it! I am storing those images in xcassets, as thats the preferred way I guess.
the app shouldnt have more than 25 mbs, I think.
I figured out that I had some references doubled in my project. I removed these and still my .app file is 89 mbs!
What am I doing wrong? I read several threads on this, but nothing really helped!
What I did until now:
- reduce the size of all pngs
- disable the compress PNG option, as it seems to make the PNGs bigger (lol)
- configured the build settings to run the fastest and smallest build
- Strip Debug Symbols During Copy build setting to Yes (COPY_PHASE_STRIP = YES)
edit1: Apparenty Xcode does something weird with my pngs. Some of those pictures, that are 2 mb originally, are more than 10mb in the .app-file. What does xcode do there ?
It is actually not surprising that the Apple recompressed files are bigger. They are optimized for fast load not small size. If you do not care about size over speed, defiantly do turn off the compression. Even if you do care about speed you can do better than Apple.
https://imageoptim.com/xcode.html
So yes, turn off the PNG compression. The first thing I would do is build the ipa. An ipa is actually a zip file so build the ipa, copy it to a folder on your mac, rename the file with a .zip extension and double click on it. This will expanded it. Find the app in the Payload folder and right mouse click on it and choose show package contents. You will see all the assets. Sort by size. I am guessing you have overly large images. At that size my guess is that the extra size is likely to be caused almost entirely by the PNG files.
Consider using non retina images for some. Honestly most people wont notice. iOS will gracefully use the non retina on retina. This can save a ton of space,
Also consider using jpeg files instead of PNG for some of the files if you do not need transparency. Jpeg files are less efficient but can be much smaller. Compare both. Depends on the extent to which the images are continuous tone.
By default PNG file are 32 bit. 24 bit color and 8 buit alpha/transparency. You can save a bit of size by going to 24 bit. You can also save a lot of size going to 16 bit color or below. At 8 bit PNG files use a color lookup table. Play with Photoshop and the save for we options at PNG with bit depth 8 and below.
I have all sorts of expensive compressing software but often use the $8
https://itunes.apple.com/us/app/lossless-photo-squeezer/id704083918?mt=12
Try the 8 bit PNG option and the JPEG options.
EDIT
I did some research. I had always know Fireworks did better PNG compression. I did not realize that there was an 8bit PNG with an 8 Bit alpha channel. Photoshop supports 8 bit with a 1 bit Alpha Channel. I have always told people to use 32 bit PNG if their transparency needed more than 1 bit. In the future I will let them know the 8 bit with 8 bit alpha may be the better route, They just can use Photoshop for the final save of the file. They just need to save a 32 bit and compress elsewhere.
http://calendar.perfplanet.com/2010/png-that-works/
David

Capturing image at higher resolution in iOS

Currently i am working on an image app where i am able to capture an image by using AVFoundation framework. But what i am looking is , to capture an image with certain resolution and DPI (may be 300 DPI or greater).
How to do this ?
There have been numerous posts on here about trying to do OCR on camera generated images. The problem is not that the resolution is too low, but that its too high. I cannot find a link right now, but there was a question a year or so ago where in the end, if the image size was reduced by a factor of four or so, the OCR engine worked better. If you examine the image in Preview, what you want is the number of pixels per character to be say 16x16 or 32x32, not 256x256. Frankly I don't know the exact number but I'm sure you can research this and find posts from actual framework users telling you the best size.
Here is a nice response on how to best scale a large image (with a link to code).

Compressing a PNG for use with CIFilter

I have an iPhone app that overlays an image over a view created by a XIB, using CIFilter CIHardLightBlendMode. The view is 1000x1000 pixels, and I want to maintain that size until the end. This makes the image files about 1 MB as a png, if there is any complexity.
I've tried using JPGs, but it doesn't overlay the image onto the view on a device (it works on the simulator). I've tried compressing the PNGs, but they get garbled when they get overlaid over the view (they look identical to the full quality ones until they are overlaid). Also, when XCode re-compresses the PNGs to the special iOS version, the compression size savings are lost.
I really would like to compress the files somewhat, but I'm not sure what will work with CIFilter. Any tips?
Thanks to this article - Clever PNG Optimization Techniques - I found a trick that reduced the file size.
Posterization reduced the file size from 1.3 MB to 458 KB (and 326 KB after XCode optimization!). This is a huge savings. My photos (textures) can be heavily posterized, so I'm not sure that this will work quite as well in other situations.
If you are interested in a new approach that reduces compressed image file size, I have created and iOS framework that compresses PNG images into a more compact form called PNGSquared. It is somewhat like the posterization approach, but you have more control over quality.

iOS vs Photoshop JPEG Compression

I have a simple question for anyone who knows the answer to this... I am making a social photo sharing app and I want to save a large enough image in the app so that it can be used in a full screen website app moving forward. Think...Facebook.
I've been playing around with JPEG compression in iOS and also testing sizes and quality with Photoshop CS5. I get really different results with these two. In photoshop, even at high compression, the image is quite clear and retains lots of detail. In iOS, once the compression dips below about 0.5 it looks horrible and blocky. It almost seems like there's a point where the image quality just dips after a certain magic compression number.
With photoshop, I use the "Save for Web" option and with iOS I am using UIImageJPEGRepresentation(image, 0.6). Is there a huge difference in these two? Aren't all JPEGs use the same kind of compression?
I am really not that informed in this world of image processing. Can anyone advice me on what is a good way to have images compressed to a level that preserves quality and stay bandwidth friendly? I want my images to stay about 1280px in length.
Any advice on this or smarter ways to move JPEGS over the network is welcomed. Thank you.
If your app is producing images from an iOS device, you should continue to use UIImageJPEGRepresentation. I don't think it's productive comparing the UIKit JPEG compression to Photoshop's.
I would find a JPEG compression level you're happy with using the available UIKit APIs and go with that. When you're serving up 30+million images a second it might be worth looking at optimisations but until then leave it to UIKit.

Resources