{"id":3196,"date":"2015-01-09T12:37:45","date_gmt":"2015-01-09T18:37:45","guid":{"rendered":"http:\/\/neosmart.net\/blog\/?p=3196"},"modified":"2015-01-09T12:37:45","modified_gmt":"2015-01-09T18:37:45","slug":"free-up-space-on-an-iphone-by-compressing-your-photo-album","status":"publish","type":"post","link":"https:\/\/neosmart.net\/blog\/free-up-space-on-an-iphone-by-compressing-your-photo-album\/","title":{"rendered":"Free up space on an iPhone by compressing your photo album"},"content":{"rendered":"<p>Most people that have had iPhones for more than a year or two have accumulated a massive amount of photos, at least several gigabytes in size. With iPhones still only shipping with a puny 16 GiB of storage by default (unless you pony up the $100 for a huge jump to the 64 GiB model with the iPhone 6\/6+), Apple has been making a lot of money off of people looking to keep their photos and still have room to take more. But there&#8217;s another option: you can optimize and compress your existing photos to make them take up less space, and recover free space for your use.<\/p>\n<p>Using the right tools and depending on the nature of your photos and images, you&#8217;ll be able to recover anywhere from 5% to 20% of your photo album size with these instructions!<\/p>\n<p><!--more--><\/p>\n<p>Depending on the whether or not your iPhone is jailbroken, you&#8217;ll be able to carry out the instructions in either one or two passes. Note that there are a lot of various utilities and tools used below, you&#8217;ll need to obtain them by downloading from the respective websites, building from source, or using a package manager (apt, brew, yum, pkg, etc).<\/p>\n<p>Requirements:<\/p>\n<ul>\n<li><a href=\"http:\/\/fuse.sourceforge.net\/sshfs.html\" rel=\"follow\">sshfs<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/mozilla\/mozjpeg\" rel=\"nofollow\">mozjpeg<\/a><\/li>\n<li><a href=\"http:\/\/pmt.sourceforge.net\/pngcrush\/\" rel=\"follow\">pngcrush<\/a><\/li>\n<li><a href=\"http:\/\/www.gnu.org\/software\/parallel\/\" rel=\"follow\">gnu parallel<\/a><\/li>\n<li><a href=\"https:\/\/code.google.com\/p\/iphonetunnel-usbmuxconnectbyport\/downloads\/list\" rel=\"follow\">itunnel<\/a><\/li>\n<\/ul>\n<p>If you have a jailbroken iPhone, you can connect directly to the iPhone and carry out the image optimization over ssh (via sshfs). For best performance and reliability, we&#8217;ll set up a TCP\/IP tunnel over USB instead of connecting over the wi-fi, using itunnel:<\/p>\n<pre class=\"p1\"><span class=\"s1\">.\/itnl --lport 9990 --iport 22 &amp;<\/span><\/pre>\n<p class=\"p1\">And then mount the iPhone over SSH:<\/p>\n<pre class=\"p1\">mkdir \/Volumes\/iPhone<br \/>\r\nsshfs -p9990 -o reconnect -C root@localhost:\/ \/Volumes\/iPhone\/<\/pre>\n<p class=\"p1\">And then CD into the photos directory:<\/p>\n<pre class=\"p1\">cd \/Volumes\/iPhone\/var\/mobile\/Media\/DCIM\/<\/pre>\n<p>If your iPhone isn&#8217;t jailbroken, what we&#8217;ll do instead is create a backup via iTunes, CD into the backup directory, then optimize the images on the local PC. Once that&#8217;s done, we can restore the backup to the iPhone with the new images.<\/p>\n<p>Next, we&#8217;ll optimize the images in three steps:<\/p>\n<pre class=\"p1\"><span class=\"s1\">find . -iname \"*.png\"\u00a0| parallel -j 8 --verbose 'pngcrush -brute {} {}2 &amp;&amp; mv {}2 {}' \\;<\/span><\/pre>\n<p class=\"p1\">This command uses pngcrush to optimize all PNG images, usually created by taking screenshots or saving images from the web. You can remove the -brute parameter to speed up the process significantly, at the cost of lower space savings.<\/p>\n<p class=\"p1\">Note: While pngcrush can read and write to the same file in a single pass (by specifying -ow to overwrite), this is\u00a0<em>not<\/em>\u00a0threadsafe\u00a0as it will write to a temporary file of the same name for all threads! As such, we manually specify the new file name and then move it back to overwrite the original.<\/p>\n<pre class=\"p1\"><span class=\"s1\">find . -iname \"*.jpg\"\u00a0|\u00a0parallel -j 8 --verbose jpegtran -copy none -optimize -outfile {} {} \\;<\/span><\/pre>\n<p class=\"p1\">This step uses jpegtran (preferably the mozjpeg version) to optimize all JPEG images, the default format used by the camera app on the iPhone. As jpegtran does not use a lot of CPU resources, we use 32 threads on an 8-core machine to completely saturate the USB link. You can experiment with the job count for best performance.<\/p>\n<pre class=\"p1\"><span class=\"s1\">find . -iname \"*.thm\"\u00a0|\u00a0parallel -j 8 --verbose 'cjpeg -quality 75 -optimize {} &gt; {}2 &amp;&amp; mv {}2 {}' \\; <\/span><\/pre>\n<p class=\"p1\">In this step, we recompress and optimize all thumbnails stored on the iPhone. Since thumbnails are lossy by default, we can use a lower quality version here. The degree of lossiness can be modified by changing the -quality parameter, but 75 is the most common value.<\/p>\n<p class=\"p1\">Optional: We can now re-run the above steps on \/var\/mobile\/Library\/SMS to compress PNG and JPEG attachments in messages (iMessage or SMS), to possibly save a lot more free space.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most people that have had iPhones for more than a year or two have accumulated a massive amount of photos, at least several gigabytes in size. With iPhones still only shipping with a puny 16 GiB of storage by default &hellip; <a href=\"https:\/\/neosmart.net\/blog\/free-up-space-on-an-iphone-by-compressing-your-photo-album\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":505,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[107,348],"class_list":["post-3196","post","type-post","status-publish","format-standard","hentry","category-software","tag-apple","tag-iphone"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4xDa-Py","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/users\/505"}],"replies":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/comments?post=3196"}],"version-history":[{"count":8,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3196\/revisions"}],"predecessor-version":[{"id":3204,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/3196\/revisions\/3204"}],"wp:attachment":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/media?parent=3196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/categories?post=3196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/tags?post=3196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}