# Default guess for the type of an image from extension
-my @simple_types = qw(png tga gif raw ico cur xpm mng jng ilbm pcx psd eps);
+my @simple_types = qw(png tga gif raw ico cur xpm mng jng ilbm pcx psd eps webp xwd xpm dng ras);
my %ext_types =
(
return $type;
}
+sub add_type_extensions {
+ my ($class, $type, @exts) = @_;
+
+ for my $ext (@exts) {
+ exists $ext_types{lc $ext} or $ext_types{lc $ext} = lc $type;
+ }
+ 1;
+}
+
sub combines {
return @combine_types;
}
addtag() - L<Imager::ImageTypes/addtag()> - add image tags
+add_type_extensions() -
+L<Imager::Files/add_type_extensions($type, $ext, ...)> - add extensions for
+new image file types.
+
align_string() - L<Imager::Draw/align_string()> - draw text aligned on a
point
=back
+=item add_type_extensions($type, $ext, ...)
+
+This class method can be used to add extensions to the map used by
+C<def_guess_type> when working out the file type a filename extension.
+
+ Imager->add_type_extension(mytype => "mytype", "mytypish");
+ ...
+ $im->write(file => "foo.mytypish") # use the mytype handler
+
=back
If you name the reader module C<Imager::File::>I<your-format-name>
# the file format
use strict;
-use Test::More tests => 94;
+use Test::More;
use Imager;
-d "testout" or mkdir "testout";
ILBM => "ilbm",
pcx => "pcx",
psd => "psd",
+ webp => "webp",
);
while (my ($ext, $expect) = splice(@tests, 0, 2)) {
is(Imager::def_guess_type($filename), $expect,
"type for $filename should be $expect");
}
+ Imager->add_type_extensions("x123", "x321");
+ is(Imager::def_guess_type("foo.x321"), "x123",
+ "test adding a file type works");
}
Imager->close_log;
+done_testing();
+
unless ($ENV{IMAGER_KEEP_FILES}) {
unlink "testout/t1000files.log";
}