Skip to content

Commit

Permalink
Convert iPhone-mangled PNG files to standard PNG format.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 20, 2019
1 parent 4047ea0 commit dad3ba1
Show file tree
Hide file tree
Showing 4 changed files with 6,361 additions and 0 deletions.
13 changes: 13 additions & 0 deletions archive_imessage.pl
Expand Up @@ -257,6 +257,13 @@ sub load_attachment {

my $is_image = $mimetype =~ /\Aimage\//;
my $is_video = $mimetype =~ /\Avideo\//;

# Temporary hack to make iPhone PNGs ( http://iphonedevwiki.net/index.php/CgBI_file_format ) look like normal PNGs.
if ($is_image) {
system("$program_dir/pngdefry -s-defried '$hashedfname' >/dev/null");
move("$hashedfname-defried.png", $hashedfname) if ( -f "$hashedfname-defried.png");
}

if ((defined $attachment_shrink_percent) && ($is_image || $is_video)) {
my $is_jpeg = check_jpegness($mimetype, $hashedfname);
my $fmt = $is_jpeg ? '-f mjpeg' : '';
Expand Down Expand Up @@ -1154,6 +1161,12 @@ sub talk_gap {
}
$htmltext =~ s#\xEF\xBF\xBC#[Missing image '$fnameimg']<br/>\n#;
} else {
# Temporary hack to make iPhone PNGs ( http://iphonedevwiki.net/index.php/CgBI_file_format ) look like normal PNGs.
if ($is_image) {
system("$program_dir/pngdefry -s-defried '$hashedfname' >/dev/null");
move("$hashedfname-defried.png", $hashedfname) if ( -f "$hashedfname-defried.png");
}

$fnameimg =~ s#.*/##;
my $orientation = get_image_orientation($hashedfname);

Expand Down
80 changes: 80 additions & 0 deletions pngdefry-1.2/man/pngdefry.1
@@ -0,0 +1,80 @@
.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
.\"See Also:
.\"man mdoc.samples for a complete listing of options
.\"man mdoc for the short list of editing options
.\"/usr/share/misc/mdoc.template
.Dd 22/1/12 \" DATE
.Dt pngdefry 1 \" Program name and manual section number
.Os OSX 10.7.2
.Sh NAME \" Section Header - required - don't modify
.Nm pngdefry
.Nd Removes -iphone optimization from PNG images.
.Sh SYNOPSIS \" Section Header - required - don't modify
.Nm
.Op Fl s Ar suffix
.Op Fl o Ar path
.Op Fl i Ar size
.Op Fl alvpd \" [-abcd]
.Op Fl
.Ar file \" [file]
.Op Ar file ...
.Sh OPTIONS
.Bl -tag -width -indent \" Differs from above in tag removed
.It Fl s Ar suffix \"-a flag as a list item
Appends
.Pa suffix
to the original filename to create the output filename.
.It Fl o Ar path
Writes output file(s) to
.Pa path .
Note: without
.Fl s
or
.Fl o ,
NO output will be created.
.It Fl i Ar size
Max IDAT chunk size in bytes (minimum: 1024; default: 524288).
.It Fl a
Do NOT de-multiply alpha. Default is it does.
.It Fl l
Lists all chunks.
.It Fl v
Verbose processing.
.It Fl p
Processes all files, not just
.Fl iphone
compressed ones (for debugging purposes only).
.It Fl d
Very verbose processing (for debugging purposes only).
.It Fl
End the list of arguments if the first filename starts with an '-'.
.El \" Ends the list
.Sh DESCRIPTION \" Section Header - required - don't modify
.Nm
attempts to remove
.Fl iphone
optimization from PNG files that are processed with Apple's modified
.Xr pngcrush .
.Pp
It removes the private critical data chunk
.Li CgBI
if this is at the very start of the PNG file, unpacks
.Li IDAT
chunks, reverses BGR(A) pixel order to RGB(A), undoes pre-multiplied alpha, repacks
.Li IDAT
chunks, and outputs all to a new file.
This is a command-line program with batch capabilities (e.g.,
.Li pngdefry *.png
).
.Sh SEE ALSO
.Xr pngcheck 1 ,
.Xr pngcrush 1
.\" .Sh BUGS \" Document known, unremedied bugs
.\" To follow, I guess.
.\" .Sh HISTORY \" Document history if command behaves in a unique manner
.Sh AUTHOR
.Nm
is written by
.An Jongware Aq jongware@hotmail.com

For more information and updates, please visit <http://www.jongware.com/pngdefry.html>

0 comments on commit dad3ba1

Please sign in to comment.