| 1 | use strict; |
| 2 | |
| 3 | use File::Path (); |
| 4 | use File::Spec::Functions; |
| 5 | use FindBin (); |
| 6 | use Test::More; |
| 7 | |
| 8 | use Image::Scale; |
| 9 | |
| 10 | eval { require Path::Tiny }; |
| 11 | if ( $@ ) { |
| 12 | plan skip_all => 'Path::Tiny not installed'; |
| 13 | } |
| 14 | |
| 15 | plan tests => 3; |
| 16 | |
| 17 | my $tmpdir = catdir( $FindBin::Bin, 'tmp' ); |
| 18 | if ( -d $tmpdir ) { |
| 19 | File::Path::rmtree($tmpdir); |
| 20 | } |
| 21 | mkdir $tmpdir; |
| 22 | |
| 23 | # Test Path::Tiny stringification |
| 24 | SKIP: |
| 25 | { |
| 26 | skip "Image::Scale not built with libjpeg support", 2 unless Image::Scale->jpeg_version; |
| 27 | |
| 28 | my $im = Image::Scale->new( Path::Tiny::path( _f("jpg/rgb.jpg") ) ); |
| 29 | is( $im->width, 313, "Path::Tiny stringify in new() ok" ); |
| 30 | |
| 31 | $im->resize_gd( { width => 50, height => 50 } ); |
| 32 | |
| 33 | my $outjpg = _tmp("resized.jpg"); |
| 34 | $im->save_jpeg( Path::Tiny::path($outjpg) ); |
| 35 | ok( -e $outjpg, 'Path::Tiny stringify in save_jpeg() ok' ); |
| 36 | } |
| 37 | |
| 38 | SKIP: |
| 39 | { |
| 40 | skip "Image::Scale not built with libpng support", 1 unless Image::Scale->png_version; |
| 41 | |
| 42 | my $im = Image::Scale->new( _f("png/rgb.png") ); |
| 43 | |
| 44 | $im->resize_gd( { width => 50, height => 50 } ); |
| 45 | |
| 46 | my $outpng = _tmp("resized.png"); |
| 47 | $im->save_png( Path::Tiny::path($outpng) ); |
| 48 | ok( -e $outpng, 'Path::Tiny stringify in save_png() ok' ); |
| 49 | } |
| 50 | |
| 51 | sub _f { |
| 52 | return catfile( $FindBin::Bin, 'images', shift ); |
| 53 | } |
| 54 | |
| 55 | sub _tmp { |
| 56 | return catfile( $tmpdir, shift ); |
| 57 | } |