Skip to content

Instantly share code, notes, and snippets.

@dylanwh
Created January 14, 2016 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanwh/97e4497d87b5b9062be5 to your computer and use it in GitHub Desktop.
Save dylanwh/97e4497d87b5b9062be5 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use autodie;
use Image::Magick;
use IO::File;
use Scalar::Util 'isdual';
use feature 'say';
my $fh = IO::File->new(shift @ARGV, "r+");
my $img = Image::Magick->new( magick => 'bmp' );
my $data = $fh;
# $data is a filehandle.
if ( ref $data ) {
warn "file based\n";
my $error = $img->Read( file => \*$data );
say $error, " :: ", $error + 0;
say isdual($error) ? "is dual var" : "is not dual var";
my $set = $img->set( magick => 'png' );
say "set: $set";
open my $out, '>result.png';
my $wrote = $img->Write( file => $out );
say "wrote: ", $wrote + 0;
}
else {
warn "string based\n";
my $result = $img->BlobToImage($data);
say $result;
$img->set( magick => 'png' );
$data = $img->ImageToBlob();
say length($data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment