Created
January 14, 2016 16:09
-
-
Save dylanwh/97e4497d87b5b9062be5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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