site/cgi-bin/modules/BSE/ImageHandler/Base.pm
site/cgi-bin/modules/BSE/ImageHandler/Flash.pm
site/cgi-bin/modules/BSE/ImageHandler/Img.pm
+site/cgi-bin/modules/BSE/ImageHandler/Svg.pm
+site/cgi-bin/modules/BSE/ImageSize.pm
site/cgi-bin/modules/BSE/Importer.pm
site/cgi-bin/modules/BSE/Importer/Source/Base.pm
site/cgi-bin/modules/BSE/Importer/Source/CSV.pm
use constant MAX_FILE_DISPLAYNAME_LENGTH => 255;
use constant ARTICLE_CUSTOM_FIELDS_CFG => "article custom fields";
-our $VERSION = "1.045";
+our $VERSION = "1.046";
=head1 NAME
close OUTPUT
or die "Could not close image output file: $!";
- use Image::Size;
+ require BSE::ImageSize;
if ($original && $original->{thumbImage}) {
#unlink("$imagedir/$original->{thumbImage}");
}
- @$newdata{qw/thumbWidth thumbHeight/} = imgsize("$imagedir/$filename");
+ @$newdata{qw/thumbWidth thumbHeight/} =
+ BSE::ImageSize::imgsize("$imagedir/$filename");
$newdata->{thumbImage} = $filename;
}
}
$imagename =~ /([\w.-]+)$/ and $basename = $1;
# for OSs with special text line endings
- use Image::Size;
+ require BSE::ImageSize;
- my($width,$height, $type) = imgsize($fh);
+ my ($width,$height, $type) = BSE::ImageSize::imgsize($fh);
unless (defined $width) {
$$error = "Unknown image file type";
}
my $full_filename = "$image_dir/$image_name";
- require Image::Size;
$delete_file = $image->{image};
$image->{image} = $image_name;
$image->{width} = $width;
my $notes = $cgi->param("notes");
defined $notes and $file->{notes} = $notes;
my $name = $cgi->param("name");
+ require BSE::ImageSize;
if (defined $name) {
$file->{name} = $name;
if (length $name) {
my $up = $cgi->upload($cgi_name);
if (defined $im && $up) {
my $data = do { local $/; <$up> };
- my ($width, $height, $type) = imgsize(\$data);
+ my ($width, $height, $type) =
+ BSE::ImageSize::imgsize(\$data);
if ($width && $height) {
push @meta,
--- /dev/null
+package BSE::ImageHandler::Svg;
+use strict;
+use base 'BSE::ImageHandler::Img';
+use BSE::Util::HTML;
+use Carp qw(confess);
+
+our $VERSION = "1.000";
+
+sub _make_thumb_hash {
+ my ($self, $geo_id, $im, $static, $abs_urls) = @_;
+
+ my $cfg = $self->cfg;
+ my $debug = $cfg->entry('debug', 'thumbnails', 0);
+
+ $static ||= 0;
+
+ $debug
+ and print STDERR "_make_thumb_hash(..., $geo_id, $im->{src}, ..., $static)\n";
+
+ $geo_id =~ /^[\w,]+$/
+ or return ( undef, "* invalid geometry id *" );
+
+ my $geometry = $cfg->entry('thumb geometries', $geo_id)
+ or return ( undef, "* cannot find thumb geometry $geo_id *" );
+
+ my $thumbs_class = $cfg->entry('editor', 'thumbs_class')
+ or return ( undef, '* no thumbnail engine configured *' );
+
+ (my $thumbs_file = $thumbs_class . ".pm") =~ s!::!/!g;
+ require $thumbs_file;
+ my $thumbs = $thumbs_class->new($cfg);
+
+ $debug
+ and print STDERR " Thumb class $thumbs_class\n";
+
+ my $error;
+ $thumbs->validate_geometry($geometry, \$error)
+ or return ( undef, "* invalid geometry string: $error *" );
+
+ my %im = map { $_ => $im->{$_} } $im->columns;
+
+ @im{qw/width height type original/} =
+ $thumbs->thumb_dimensions_sized($geometry, @$im{qw/width height/});
+
+ $im{image} = $im->src;
+
+ if ($abs_urls && $im{image} !~ /^\w+:/) {
+ $im{image} = $cfg->entryVar('site', 'url') . $im{image};
+ }
+
+ $im{src} = $im{image};
+
+ return \%im;
+}
+
+1;
+
+=head1 NAME
+
+BSE::ImageHandler::Svg - handle "image" display for SVG
+
+=head1 DESCRIPTION
+
+This module provides display rendering and limited thumbnail rendering
+for SVG content in the image manager.
+
+=cut
--- /dev/null
+package BSE::ImageSize;
+use strict;
+use Image::Size ();
+use Fcntl ':seek';
+
+our $VERSION = "1.000";
+
+use Exporter 'import';
+use Scalar::Util qw(reftype);
+
+our @EXPORT_OK = qw(imgsize);
+
+=head1 NAME
+
+BSE::ImageSize - wrapper around Image::Size, adds SVG support
+
+=head1 SYNOPSIS
+
+ use BSE::ImageSize "imgsize";
+ my ($width, $height, $type) = imgsize($fh);
+ my ($width, $height, $type) = imgsize($filename);
+ my ($width, $height, $type) = imgsize(\$buf);
+
+=head1 DESCRIPTION
+
+Retrieve the size of the given image file.
+
+On error, returns $width and $height as undef and sets $type to the
+error.
+
+=cut
+
+sub imgsize {
+ my ($fh) = @_;
+
+ my ($width, $height, $type) = Image::Size::imgsize($fh);
+
+ unless (defined $width) {
+ my $info = _parse_svg($fh);
+ if (ref $fh && reftype $fh ne "SCALAR") {
+ seek $fh, 0, SEEK_SET;
+ }
+ unless ($info->{error}) {
+ ($width, $height, $type) = @{$info}{qw(width height file_type)};
+ }
+ }
+
+ return ( $width, $height, $type );
+}
+
+sub _parse_svg {
+ my ($file) = @_;
+
+ require XML::Parser;
+
+ my $io;
+ if (ref $file) {
+ if (reftype $file eq "SCALAR") {
+ # IO::Scalar
+ $io = $$file;
+ }
+ else {
+ $io = $file;
+ binmode $io;
+ }
+ }
+ else {
+ open $io, "<", $file;
+ binmode $file;
+ }
+
+ my ($width, $height, $vb);
+ my $parser = XML::Parser->new
+ (
+ Handlers =>
+ {
+ Start => sub {
+ my ($self, $elem, %attr) = @_;
+
+ if ($elem =~ /\bsvg$/) {
+ $width = $attr{width};
+ $height = $attr{height};
+ $vb = $attr{viewBox};
+ $self->finish;
+ }
+ },
+ },
+ );
+ eval { $parser->parse($io) }
+ or return;
+
+ SKIP:
+ {
+ $width && $height
+ or last SKIP;
+ $width =~ /^(\d+)\s*(px)?$/
+ or last SKIP;
+ $width = $1;
+ $height =~ /^(\d+)\s*(px)?$/
+ or last SKIP;
+ $height = $1;
+ return +{ width => $width, height => $height, file_type => "SVG" };
+ }
+
+ $vb or return;
+
+ ( undef, undef, $width, $height) = split /[\s,]/, $vb;
+ $width && $height
+ or return;
+
+ return +{ width => $width, height => $height, file_type => "SVG" };
+}
+
+1;
+
+=head1 AUTHOR
+
+Tony Cook <tony@develop-help.com>
+
+=cut
+
@ISA = qw/Squirrel::Row BSE::ThumbCommon BSE::TB::TagOwner/;
use Carp qw(confess);
-our $VERSION = "1.008";
+our $VERSION = "1.009";
=head1 NAME
=item ftype
-the type of image, either C<img> for normal images, or C<flash> for
-flash files.
+the type of image, either C<img> for normal images, C<svg> for SVG
+images or C<flash> for flash files.
=cut
or die "$msg\n";
my $full_filename = "$image_dir/$image_name";
- require Image::Size;
- my ($width, $height, $type) = Image::Size::imgsize($full_filename);
+ require BSE::ImageSize;
+ my ($width, $height, $type) = BSE::ImageSize::imgsize($full_filename);
if ($width) {
$delete_file = $image->image;
$image->set_image($image_name);
@ISA = qw(Squirrel::Table BSE::TB::TagOwners);
use BSE::TB::Image;
-our $VERSION = "1.004";
+our $VERSION = "1.005";
sub rowClass {
return 'BSE::TB::Image';
if ($type eq 'CWS' || $type eq 'SWF') {
return "flash";
}
+ elsif ($type eq 'SVG') {
+ return "svg";
+ }
return "img";
}
use BSE::Util::HTML;
use BSE::Util::Tags qw(tag_hash);
-our $VERSION = "1.000";
+our $VERSION = "1.001";
use constant MAXWIDTH => 10000;
use constant MAXHEIGHT => 10000;
my $image_dir = $cfg->entryVar('paths', 'siteuser_images');
require DevHelp::FileUpload;
- require Image::Size;
+ require BSE::ImageSize;
my @new_files;
push @new_files, $work_fullname;
# image parameter validation
- my ($width, $height, $type) = Image::Size::imgsize($work_fullname);
+ my ($width, $height, $type) = BSE::ImageSize::imgsize($work_fullname);
unless (defined $width) {
$errors->{$file_param} = "Error determining image size: $type";
unlink $work_fullname;