Hacker Public Radio

HPR2730: Resizing images for vcard on Android


Listen Later

I have had problems importing vcards onto my Android phone. After a lot of troubleshooting, I tracked it down to embedded images in the card. The PHOTO;VALUE field to be precise.
Some images worked and some didn't, and looking at the properties some that worked were larger than others that didn't. In the end I tracked down a post on stackoverflow that hinted that the aspect ratio was important. And sure enough it was.
starting with jelly bean (4.1), android now supports contact images that are 720x720.before, starting with ICS (4.0), android has supported contact images that are 256x256.and before that, contact photos had just a size of a thumbnail - 96x96.
Stack exchange
I tried a 720x720 on a few phones but decided to settle on 256x256 for now.
To do image manipulation, I tend to use the GraphicsMagick tools instead of the more popular ImageMagick suite. You should be able to achieve the same result in either.
My requirements were:
The images should be scaled so that the maximum height/width shrinks to 256, maintaining the aspect ratio.
The images should always be 256x256 in size.
Scaled images should be padded and centered on a white background.
All color profile information should be removed.
To use an example I took the following image and saved it as Linus_Torvalds.jpg
By Krd (photo)Von Sprat (crop/extraction) - File:LinuxCon Europe Linus Torvalds 03.jpg, CC BY-SA 4.0, Link
Step one is to use the -size 256x256 option which you would think would do the scaling, but in fact it only reduces the file to 366x509 which is not what I expected.
$ gm convert -size 256x256 "Linus_Torvalds.jpg" Linus_Torvalds_1.jpg$ gm identify Linus_Torvalds_1.jpg
Linus_Torvalds_1.jpg JPEG 366x509+0+0 DirectClass 8-bit 56.1Ki 0.000u 0m:0.000002
However it appears that the option is used when creating new files, and is also used by the processor to determine the intended target size. Which is why I left it in. So what we actually need is the -resize option.
$ gm convert -size 256x256 "Linus_Torvalds.jpg" -resize 256x256 Linus_Torvalds_2.jpg
$ gm identify Linus_Torvalds_2.jpg
Linus_Torvalds_2.jpg JPEG 184x256+0+0 DirectClass 8-bit 47.7Ki 0.000u 0m:0.000001s
So this has done a good job at scaling the image down. It's now scaled correctly so that the biggest edge is scaled down to 256. In this case it was the height but the width is now shorter than what we need. We do want to maintain the aspect rat
...more
View all episodesView all episodes
Download on the App Store

Hacker Public RadioBy Hacker Public Radio

  • 4.2
  • 4.2
  • 4.2
  • 4.2
  • 4.2

4.2

34 ratings


More shows like Hacker Public Radio

View all
The Infinite Monkey Cage by BBC Radio 4

The Infinite Monkey Cage

1,952 Listeners

Click Here by Recorded Future News

Click Here

418 Listeners

Hacker And The Fed by Chris Tarbell & Hector Monsegur

Hacker And The Fed

168 Listeners