more bug fixes
This commit is contained in:
parent
9238c028c6
commit
864206b05b
7 changed files with 33 additions and 139 deletions
|
|
@ -248,7 +248,6 @@ sub view {
|
|||
my $self = shift;
|
||||
my %var = %{$self->get};
|
||||
$var{controls} = $self->getToolbar;
|
||||
$var{controls} = '<p>'.$var{controls}.'</p>' if (exists $var{controls});
|
||||
$var{fileUrl} = $self->getFileUrl;
|
||||
$var{fileIcon} = $self->getFileIconUrl;
|
||||
return $self->processTemplate(\%var,"PBtmpl0000000000000024");
|
||||
|
|
|
|||
|
|
@ -193,7 +193,6 @@ sub view {
|
|||
my $self = shift;
|
||||
my %var = %{$self->get};
|
||||
$var{controls} = $self->getToolbar;
|
||||
$var{controls} = '<p>'.$var{controls}.'</p>' if (exists $var{controls});
|
||||
$var{fileUrl} = $self->getFileUrl;
|
||||
$var{fileIcon} = $self->getFileIconUrl;
|
||||
$var{thumbnail} = $self->getThumbnailUrl;
|
||||
|
|
|
|||
|
|
@ -111,6 +111,11 @@ sub getEditForm {
|
|||
$tabform->getTab("properties")->readOnly(
|
||||
-label=>"Relatives to Include",
|
||||
-value=>WebGUI::Form::checkbox({
|
||||
checked=>$selfChecked,
|
||||
name=>"assetsToInclude",
|
||||
value=>"ancestors"
|
||||
}).'Ancestors<br />'
|
||||
.WebGUI::Form::checkbox({
|
||||
checked=>$selfChecked,
|
||||
name=>"assetsToInclude",
|
||||
value=>"self"
|
||||
|
|
|
|||
|
|
@ -1,125 +0,0 @@
|
|||
package WebGUI::Macro::SI_scaledImage;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Collateral;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Utility;
|
||||
|
||||
# test for Image::Magick
|
||||
|
||||
# (Would be nice if the results of this test were availiable somewhere
|
||||
# central)
|
||||
|
||||
my $hasImageMagick=1;
|
||||
eval " use Image::Magick; "; $hasImageMagick=0 if $@;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _getImage {
|
||||
my ($collateral) = @_;
|
||||
return undef unless ($hasImageMagick);
|
||||
my $image = Image::Magick->new();
|
||||
if (my $error = $image->Read($collateral->getPath)) {
|
||||
WebGUI::ErrorHandler::warn("Couldn't read image for resizing: ".$error);
|
||||
return undef;
|
||||
}
|
||||
return $image;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my ($collateralIdent,$width,$height,$parameters) = WebGUI::Macro::getParams($_[0]);
|
||||
my ($collateral,$url);
|
||||
|
||||
if ($collateralIdent =~ /[\w|\-]{22}/) {
|
||||
$collateral = WebGUI::Collateral->new($collateralIdent);
|
||||
}
|
||||
else {
|
||||
$collateral = WebGUI::Collateral->find($collateralIdent);
|
||||
}
|
||||
|
||||
unless ($collateral) {
|
||||
WebGUI::ErrorHandler::warn("collateral not found: $collateralIdent");
|
||||
return '';
|
||||
}
|
||||
|
||||
unless ($collateral->isImage()) {
|
||||
WebGUI::ErrorHandler::warn("Bad image type: $collateralIdent");
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($width || $height) {
|
||||
$url = scaleImage(
|
||||
collateral => $collateral,
|
||||
width => $width,
|
||||
height => $height
|
||||
);
|
||||
}
|
||||
else {
|
||||
WebGUI::ErrorHandler::warn("width or heigth must be specified");
|
||||
}
|
||||
|
||||
$url ||= $collateral->getURL;
|
||||
|
||||
return qq!<img src="$url" $parameters/>!;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub scaleImage {
|
||||
my (%p) = @_;
|
||||
|
||||
my ($collateral,$width,$height) = @p{qw(collateral width height)};
|
||||
|
||||
# paranoia
|
||||
return undef unless ($height || $width);
|
||||
|
||||
my $filename = "SIThumb_".($width || 'r')."x".($height || 'r')."_".$collateral->getFilename();
|
||||
$filename .= '.png' if (isIn($collateral->getType(), qw(tif tiff bmp)));
|
||||
|
||||
my $pathName = $collateral->{_node}->getPath().$session{os}{slash}.$filename;
|
||||
unless (-e $pathName) {
|
||||
my $image = _getImage($collateral);
|
||||
return undef unless $image;
|
||||
my ($newWidth,$newHeight);
|
||||
|
||||
if ($width && $height) {
|
||||
($newWidth,$newHeight) = ($width,$height);
|
||||
}
|
||||
else {
|
||||
my ($x, $y) = $image->Get('width','height');
|
||||
my $ratio = $x / $y;
|
||||
$newWidth = $width ? $width : $height * $ratio;
|
||||
$newHeight = $height ? $height : $width / $ratio;
|
||||
}
|
||||
|
||||
my $max = $session{setting}{maxImageSize};
|
||||
if ($newHeight > $max || $newWidth > $max) {
|
||||
WebGUI::ErrorHandler::warn(
|
||||
"Image too large ($newWidth,$newHeight) :".$collateral->get('name')
|
||||
);
|
||||
return undef;
|
||||
}
|
||||
|
||||
$image->Scale(width => $newWidth, height => $newHeight);
|
||||
if (my $error = $image->Write($pathName)) {
|
||||
WebGUI::ErrorHandler::warn("Couldn't resize image: ".$error);
|
||||
}
|
||||
}
|
||||
|
||||
return $collateral->{_node}->getURL."/$filename";
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue