Skip to content

Commit 25c536f

Browse files
authored
Merge pull request blueimp#3496 from jbostoen/jbostoen-patch-2
Update UploadHandler.php (fixed)
2 parents 0cc119a + 3cc1394 commit 25c536f

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

server/php/UploadHandler.php

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,22 @@ public function __construct($options = null, $initialize = true, $error_messages
131131
// Command or path for to the ImageMagick identify binary:
132132
'identify_bin' => 'identify',
133133
'image_versions' => array(
134-
// The empty image version key defines options for the original image:
135-
// Keep in mind that these options are inherited by all other image versions!
134+
// The empty image version key defines options for the original image.
135+
// Keep in mind: these image manipulations are inherited by all other image versions from this point onwards.
136+
// Also note that the property 'no_cache' is not inherited, since it's not a manipulation.
136137
'' => array(
137138
// Automatically rotate images based on EXIF meta data:
138139
'auto_orient' => true
139140
),
140-
// Uncomment the following to create medium sized images:
141+
// You can add arrays to generate different versions.
142+
// The name of the key is the name of the version (example: 'medium').
143+
// the array contains the options to apply.
141144
/*
142145
'medium' => array(
143146
'max_width' => 800,
144147
'max_height' => 600
145148
),
146-
*/
149+
*/
147150
'thumbnail' => array(
148151
// Uncomment the following to use a defined directory for the thumbnails
149152
// instead of a subdirectory based on the version identifier.
@@ -154,9 +157,13 @@ public function __construct($options = null, $initialize = true, $error_messages
154157
//'upload_url' => $this->get_full_url().'/thumb/',
155158
// Uncomment the following to force the max
156159
// dimensions and e.g. create square thumbnails:
157-
//'crop' => true,
158-
'max_width' => 80,
159-
'max_height' => 80
160+
// 'auto_orient' => true,
161+
// 'crop' => true,
162+
// 'jpeg_quality' => 70,
163+
// 'no_cache' => true, (there's a caching option, but this remembers thumbnail sizes from a previous action!)
164+
// 'strip' => true, (this strips EXIF tags, such as geolocation)
165+
'max_width' => 80, // either specify width, or set to 0. Then width is automatically adjusted - keeping aspect ratio to a specified max_height.
166+
'max_height' => 80 // either specify height, or set to 0. Then height is automatically adjusted - keeping aspect ratio to a specified max_width.
160167
)
161168
),
162169
'print_response' => true
@@ -863,26 +870,32 @@ protected function imagick_create_scaled_image($file_name, $version, $options) {
863870
$image_oriented = false;
864871
if (!empty($options['auto_orient'])) {
865872
$image_oriented = $this->imagick_orient_image($image);
866-
}
873+
}
874+
875+
$image_resize = false;
867876
$new_width = $max_width = $img_width = $image->getImageWidth();
868-
$new_height = $max_height = $img_height = $image->getImageHeight();
869-
if (!empty($options['max_width'])) {
870-
$new_width = $max_width = $options['max_width'];
871-
}
872-
if (!empty($options['max_height'])) {
877+
$new_height = $max_height = $img_height = $image->getImageHeight();
878+
879+
// use isset(). User might be setting max_width = 0 (auto in regular resizing). Value 0 would be considered empty when you use empty()
880+
if (isset($options['max_width'])) {
881+
$image_resize = true;
882+
$new_width = $max_width = $options['max_width'];
883+
}
884+
if (isset($options['max_height'])) {
885+
$image_resize = true;
873886
$new_height = $max_height = $options['max_height'];
874887
}
875-
$image_strip = false;
876-
if( !empty($options["strip"]) ) {
877-
$image_strip = $options["strip"];
878-
}
888+
889+
$image_strip = (isset($options['strip']) ? $options['strip'] : false);
890+
879891
if ( !$image_oriented && ($max_width >= $img_width) && ($max_height >= $img_height) && !$image_strip && empty($options["jpeg_quality"]) ) {
880892
if ($file_path !== $new_file_path) {
881893
return copy($file_path, $new_file_path);
882894
}
883895
return true;
884896
}
885-
$crop = !empty($options['crop']);
897+
$crop = (isset($options['crop']) ? $options['crop'] : false);
898+
886899
if ($crop) {
887900
$x = 0;
888901
$y = 0;

0 commit comments

Comments
 (0)