Skip to content

Commit 2225c79

Browse files
author
jbostoen
authored
Update UploadHandler.php
1 parent 0cc119a commit 2225c79

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

server/php/UploadHandler.php

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,18 @@ public function __construct($options = null, $initialize = true, $error_messages
132132
'identify_bin' => 'identify',
133133
'image_versions' => array(
134134
// 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!
135+
// Keep in mind: these image manipulations are inherited by all other image versions!
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 an array. The key is the name of the version, the array contains the options to apply.
141142
/*
142-
'medium' => array(
143-
'max_width' => 800,
144-
'max_height' => 600
145-
),
146-
*/
143+
'example-of-another-version' => array(
144+
'max_width' => 80,
145+
'max_height' => 80
146+
), */
147147
'thumbnail' => array(
148148
// Uncomment the following to use a defined directory for the thumbnails
149149
// instead of a subdirectory based on the version identifier.
@@ -154,9 +154,15 @@ public function __construct($options = null, $initialize = true, $error_messages
154154
//'upload_url' => $this->get_full_url().'/thumb/',
155155
// Uncomment the following to force the max
156156
// dimensions and e.g. create square thumbnails:
157-
//'crop' => true,
158-
'max_width' => 80,
159-
'max_height' => 80
157+
// 'auto_orient' => true,
158+
// 'crop' => true,
159+
// 'jpeg_quality' => 70,
160+
// 'no_cache' => true, (there's a caching option, but this remembers thumbnail sizes from a previous action!)
161+
// 'max_width' => 0, (t
162+
// 'max_height' => 200,
163+
// 'strip' => true, (this strips EXIF tags, such as geolocation)
164+
'max_width' => 80, // either specify width, or set to 0. Then width is automatically adjusted - keeping aspect ratio to a specified max_height.
165+
'max_height' => 80 // either specify height, or set to 0. Then height is automatically adjusted - keeping aspect ratio to a specified max_width.
160166
)
161167
),
162168
'print_response' => true
@@ -864,25 +870,30 @@ protected function imagick_create_scaled_image($file_name, $version, $options) {
864870
if (!empty($options['auto_orient'])) {
865871
$image_oriented = $this->imagick_orient_image($image);
866872
}
873+
$image_resize = false;
867874
$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'])) {
875+
$new_height = $max_height = $img_height = $image->getImageHeight();
876+
877+
// use isset(). User might be setting max_width = 0 (auto in regular resizing). Value 0 would be considered empty when you use empty()
878+
if (isset($options['max_width'])) {
879+
$image_resize = true;
880+
$new_width = $max_width = $options['max_width'];
881+
}
882+
if (isset($options['max_height'])) {
883+
$image_resize = true;
873884
$new_height = $max_height = $options['max_height'];
874885
}
875-
$image_strip = false;
876-
if( !empty($options["strip"]) ) {
877-
$image_strip = $options["strip"];
878-
}
886+
887+
$image_strip = (isset($options['strip']) ? $options['strip'] : false);
888+
879889
if ( !$image_oriented && ($max_width >= $img_width) && ($max_height >= $img_height) && !$image_strip && empty($options["jpeg_quality"]) ) {
880890
if ($file_path !== $new_file_path) {
881891
return copy($file_path, $new_file_path);
882892
}
883893
return true;
884894
}
885-
$crop = !empty($options['crop']);
895+
$crop = (isset($options['crop']) ? $options['crop'] : false);
896+
886897
if ($crop) {
887898
$x = 0;
888899
$y = 0;

0 commit comments

Comments
 (0)