This SUB can be used in the add success page. It accepts $ID as an argument and it will manipulate
the images based on the magick.cfg file located in the Plugins/ directory
Code for the Global
use Image::Magick;
my $cfg = do "$CFG->{admin_root_path}/Plugins/magick.cfg";
my $opts = shift || '0';
my $type = shift || 'Links'; if ($opts) {
my ($file,$width,$height,$bgcolor,$image,$quality);
# Read the Hash and iterate
while ( my ($field, $value) = each %$cfg) { $file = $DB->table($type)->file_info($field, $opts);
if ($file) { $width = $cfg->{$field}{width} || '100';
$height = $cfg->{$field}{height} || '100';
$bgcolor = $cfg->{$field}{bgcolor} || 'FFFFFF';
$quality = $cfg->{$field}{quality} || '60'; $image = Image::Magick->new;
$image->Read($file); # Image options...
$image->Scale(width=>$width,height=>$height);
$image->Set(quality=>$quality);
$image->Transparent(color=>$bgcolor); $image->Write($file);
undef $image;
}
}
}
return;
}
Contents of a sample magick.cfg file with two image fields (Image_Thumb and Image_Big)
'Image_Thumb' => {
'width' => 140,
'height' => 100,
'bgcolor' => 'FFFFFF',
'quality' => '60',
},
'Image_Big' => {
'width' => 800,
'height' => 600,
'bgcolor' => 'FFFFFF',
'quality' => '80',
},
}
This requires the Image Magick perl module installed....
Enjoy...
the images based on the magick.cfg file located in the Plugins/ directory
Code for the Global
Code:
sub { use Image::Magick;
my $cfg = do "$CFG->{admin_root_path}/Plugins/magick.cfg";
my $opts = shift || '0';
my $type = shift || 'Links'; if ($opts) {
my ($file,$width,$height,$bgcolor,$image,$quality);
# Read the Hash and iterate
while ( my ($field, $value) = each %$cfg) { $file = $DB->table($type)->file_info($field, $opts);
if ($file) { $width = $cfg->{$field}{width} || '100';
$height = $cfg->{$field}{height} || '100';
$bgcolor = $cfg->{$field}{bgcolor} || 'FFFFFF';
$quality = $cfg->{$field}{quality} || '60'; $image = Image::Magick->new;
$image->Read($file); # Image options...
$image->Scale(width=>$width,height=>$height);
$image->Set(quality=>$quality);
$image->Transparent(color=>$bgcolor); $image->Write($file);
undef $image;
}
}
}
return;
}
Contents of a sample magick.cfg file with two image fields (Image_Thumb and Image_Big)
Code:
{ 'Image_Thumb' => {
'width' => 140,
'height' => 100,
'bgcolor' => 'FFFFFF',
'quality' => '60',
},
'Image_Big' => {
'width' => 800,
'height' => 600,
'bgcolor' => 'FFFFFF',
'quality' => '80',
},
}
This requires the Image Magick perl module installed....
Enjoy...