fixed Gallery Disk Space problem by adding a way to change image density
This commit is contained in:
parent
4683e4b769
commit
b0669c1a36
6 changed files with 100 additions and 18 deletions
|
|
@ -12,6 +12,7 @@
|
||||||
- fixed: per item shipping
|
- fixed: per item shipping
|
||||||
- fixed: product title problem
|
- fixed: product title problem
|
||||||
- fixed: adding payment brings me to /
|
- fixed: adding payment brings me to /
|
||||||
|
- fixed: Gallery uses too much disk space. Added a way to change an images pixel density.
|
||||||
|
|
||||||
7.5.18
|
7.5.18
|
||||||
- fixed: Collateral Image Manager broken in Firefox 3
|
- fixed: Collateral Image Manager broken in Firefox 3
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ my $session = start(); # this line required
|
||||||
addNewInboxIndexes( $session );
|
addNewInboxIndexes( $session );
|
||||||
updateAddressTable( $session );
|
updateAddressTable( $session );
|
||||||
addProductShipping( $session );
|
addProductShipping( $session );
|
||||||
|
addGalleryImageDensity( $session );
|
||||||
correctPayDriverReceiptTemplate( $session );
|
correctPayDriverReceiptTemplate( $session );
|
||||||
finish($session); # this line required
|
finish($session); # this line required
|
||||||
|
|
||||||
|
|
@ -45,6 +46,19 @@ finish($session); # this line required
|
||||||
# print "DONE!\n" unless $quiet;
|
# print "DONE!\n" unless $quiet;
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Add the image density property to the Gallery
|
||||||
|
sub addGalleryImageDensity {
|
||||||
|
my $session = shift;
|
||||||
|
print "\tAdding Image Density to Gallery... " unless $quiet;
|
||||||
|
|
||||||
|
$session->db->write(
|
||||||
|
"ALTER TABLE Gallery ADD COLUMN imageDensity INT"
|
||||||
|
);
|
||||||
|
|
||||||
|
print "DONE!\n" unless $quiet;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Corrects the asset id of the default receipt email template for the PayDriver
|
# Corrects the asset id of the default receipt email template for the PayDriver
|
||||||
sub correctPayDriverReceiptTemplate{
|
sub correctPayDriverReceiptTemplate{
|
||||||
|
|
|
||||||
|
|
@ -109,21 +109,28 @@ C<options> is a hash reference of options and is currently not used.
|
||||||
|
|
||||||
sub applyConstraints {
|
sub applyConstraints {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
my $options = shift;
|
||||||
my $gallery = $self->getGallery;
|
my $gallery = $self->getGallery;
|
||||||
|
|
||||||
# Update the asset's size and make a thumbnail
|
# Update the asset's size and make a thumbnail
|
||||||
my $maxImageSize = $self->getGallery->get("imageViewSize")
|
my $maxImageSize = $gallery->get("imageViewSize")
|
||||||
|| $self->session->setting->get("maxImageSize");
|
|| $self->session->setting->get("maxImageSize");
|
||||||
my $thumbnailSize = $self->getGallery->get("imageThumbnailSize")
|
|
||||||
|| $self->session->setting->get("thumbnailSize");
|
|
||||||
my $parameters = $self->get("parameters");
|
my $parameters = $self->get("parameters");
|
||||||
my $storage = $self->getStorageLocation;
|
my $storage = $self->getStorageLocation;
|
||||||
my $file = $self->get("filename");
|
my $file = $self->get("filename");
|
||||||
|
|
||||||
|
# Make resolutions before fixing image, so that we can get higher quality
|
||||||
|
# resolutions
|
||||||
|
$self->makeResolutions;
|
||||||
|
|
||||||
|
# adjust density before size, so that the dimensions won't change
|
||||||
|
$storage->resize( $file, undef, undef, $gallery->get( 'imageDensity' ) );
|
||||||
$storage->adjustMaxImageSize($file, $maxImageSize);
|
$storage->adjustMaxImageSize($file, $maxImageSize);
|
||||||
|
|
||||||
$self->generateThumbnail;
|
$self->generateThumbnail;
|
||||||
$self->setSize;
|
$self->setSize;
|
||||||
$self->makeResolutions;
|
|
||||||
$self->updateExifDataFromFile;
|
$self->updateExifDataFromFile;
|
||||||
|
$self->SUPER::applyConstraints( $options );
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -361,7 +368,7 @@ sub makeResolutions {
|
||||||
}
|
}
|
||||||
my $newFilename = $res . ".jpg";
|
my $newFilename = $res . ".jpg";
|
||||||
$storage->copyFile( $self->get("filename"), $newFilename );
|
$storage->copyFile( $self->get("filename"), $newFilename );
|
||||||
$storage->resize( $newFilename, $res );
|
$storage->resize( $newFilename, $res, undef, $self->getGallery->get( 'imageDensity' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,11 @@ sub definition {
|
||||||
DESC => $i18n->get("viewListOrderDirection option desc"),
|
DESC => $i18n->get("viewListOrderDirection option desc"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
tie my %imageDensityOptions, 'Tie::IxHash', (
|
||||||
|
72 => $i18n->get( "imageDensity option web" ),
|
||||||
|
300 => $i18n->get( "imageDensity option print" ),
|
||||||
|
);
|
||||||
|
|
||||||
tie my %properties, 'Tie::IxHash', (
|
tie my %properties, 'Tie::IxHash', (
|
||||||
groupIdAddComment => {
|
groupIdAddComment => {
|
||||||
tab => "security",
|
tab => "security",
|
||||||
|
|
@ -102,6 +107,14 @@ sub definition {
|
||||||
label => $i18n->get("imageThumbnailSize label"),
|
label => $i18n->get("imageThumbnailSize label"),
|
||||||
hoverHelp => $i18n->get("imageThumbnailSize description"),
|
hoverHelp => $i18n->get("imageThumbnailSize description"),
|
||||||
},
|
},
|
||||||
|
imageDensity => {
|
||||||
|
tab => "properties",
|
||||||
|
fieldType => "selectBox",
|
||||||
|
options => \%imageDensityOptions,
|
||||||
|
defaultValue => 72,
|
||||||
|
label => $i18n->get( "imageDensity label" ),
|
||||||
|
hoverHelp => $i18n->get( "imageDensity description" ),
|
||||||
|
},
|
||||||
maxSpacePerUser => {
|
maxSpacePerUser => {
|
||||||
tab => "properties",
|
tab => "properties",
|
||||||
fieldType => "integer",
|
fieldType => "integer",
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,8 @@ sub addFileFromCaptcha {
|
||||||
return ($filename, $challenge);
|
return ($filename, $challenge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 adjustMaxImageSize ( $file )
|
=head2 adjustMaxImageSize ( $file )
|
||||||
|
|
||||||
Adjust the size of an image according to the C<maxImageSize> setting in the Admin
|
Adjust the size of an image according to the C<maxImageSize> setting in the Admin
|
||||||
|
|
@ -356,13 +358,20 @@ The new width of the image in pixels.
|
||||||
|
|
||||||
The new height of the image in pixels.
|
The new height of the image in pixels.
|
||||||
|
|
||||||
|
=head3 density
|
||||||
|
|
||||||
|
The new image density in pixels per inch.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
# TODO: Make this take a hash reference with width, height, and density keys.
|
||||||
|
|
||||||
sub resize {
|
sub resize {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $filename = shift;
|
my $filename = shift;
|
||||||
my $width = shift;
|
my $width = shift;
|
||||||
my $height = shift;
|
my $height = shift;
|
||||||
|
my $density = shift;
|
||||||
unless (defined $filename) {
|
unless (defined $filename) {
|
||||||
$self->session->errorHandler->error("Can't resize when you haven't specified a file.");
|
$self->session->errorHandler->error("Can't resize when you haven't specified a file.");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -371,7 +380,7 @@ sub resize {
|
||||||
$self->session->errorHandler->error("Can't resize something that's not an image.");
|
$self->session->errorHandler->error("Can't resize something that's not an image.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
unless ($width || $height) {
|
unless ($width || $height || $density) {
|
||||||
$self->session->errorHandler->error("Can't resize with no resizing parameters.");
|
$self->session->errorHandler->error("Can't resize with no resizing parameters.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -381,19 +390,33 @@ sub resize {
|
||||||
$self->session->errorHandler->error("Couldn't read image for resizing: ".$error);
|
$self->session->errorHandler->error("Couldn't read image for resizing: ".$error);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
my ($x, $y) = $image->Get('width','height');
|
|
||||||
if (!$height) { # proportional scale by width
|
# First, change image density
|
||||||
$height = $width / $x * $y;
|
if ( $density ) {
|
||||||
|
$self->session->errorHandler->info( "Setting $filename to $density" );
|
||||||
|
$image->Set( density => "${density}x${density}" );
|
||||||
}
|
}
|
||||||
elsif (!$width) { # proportional scale by height
|
|
||||||
$width = $height * $x / $y;
|
# Next, resize dimensions
|
||||||
|
if ( $width || $height ) {
|
||||||
|
$self->session->errorHandler->info( "Resizing $filename to w:$width h:$height" );
|
||||||
|
my ($x, $y) = $image->Get('width','height');
|
||||||
|
if (!$height) { # proportional scale by width
|
||||||
|
$height = $width / $x * $y;
|
||||||
|
}
|
||||||
|
elsif (!$width) { # proportional scale by height
|
||||||
|
$width = $height * $x / $y;
|
||||||
|
}
|
||||||
|
$image->Resize( height => $height, width => $width );
|
||||||
}
|
}
|
||||||
$image->Resize( height => $height, width => $width, filter => "lanczos" );
|
|
||||||
|
# Write our changes to disk
|
||||||
$error = $image->Write($self->getPath($filename));
|
$error = $image->Write($self->getPath($filename));
|
||||||
if ($error) {
|
if ($error) {
|
||||||
$self->session->errorHandler->error("Couldn't resize image: ".$error);
|
$self->session->errorHandler->error("Couldn't resize image: ".$error);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ our $I18N = {
|
||||||
context => '',
|
context => '',
|
||||||
},
|
},
|
||||||
"imageResolutions description" => {
|
"imageResolutions description" => {
|
||||||
message => "The sizes of images (in pixels) available for download. Images will be altered to 72 DPI before proportionally constrained to the specified number of pixels. In other words, this number is the maximum height or width that the image will have.",
|
message => "The sizes of images (in pixels) available for download. This number is the maximum height or width that the image will have.",
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
context => '',
|
context => '',
|
||||||
},
|
},
|
||||||
|
|
@ -73,7 +73,7 @@ our $I18N = {
|
||||||
context => '',
|
context => '',
|
||||||
},
|
},
|
||||||
"maxSpacePerUser description" => {
|
"maxSpacePerUser description" => {
|
||||||
message => "The maximum amount of disk space (in megabytes) a user is allowed to use in this Gallery.",
|
message => "The maximum amount of disk space (in megabytes) a user is allowed to use in this Gallery. Each image will take up to 6 megabytes depending on what resolutions and density you choose.",
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
context => '',
|
context => '',
|
||||||
},
|
},
|
||||||
|
|
@ -711,6 +711,30 @@ our $I18N = {
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
context => q{Description of asset property},
|
context => q{Description of asset property},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'imageDensity label' => {
|
||||||
|
message => q{Image Density},
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q{Label for asset property},
|
||||||
|
},
|
||||||
|
|
||||||
|
'imageDensity description' => {
|
||||||
|
message => q{The density of the image. Print-quality images are more than three times the size of web-quality images.},
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q{Description of asset property},
|
||||||
|
},
|
||||||
|
|
||||||
|
'imageDensity option web' => {
|
||||||
|
message => q{Web quality (72 pixels per inch)},
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q{Option label for 72 pixels-per-inch images, the highest that monitors can display},
|
||||||
|
},
|
||||||
|
|
||||||
|
'imageDensity option print' => {
|
||||||
|
message => q{Print quality (300 pixels per inch)},
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q{Option label for 300 pixels-per-inch images, good for printing images},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue