Skip to content

Commit d09544f

Browse files
committed
Merge pull request blueimp#3144 from jamesvl/master
Use namespaces at all times; fix capitlization issues; fix issue when uploading non-image file.
2 parents 8dc29de + 34c26f3 commit d09544f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

server/php/UploadHandler.php

100644100755
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ protected function is_valid_file_object($file_name) {
290290

291291
protected function get_file_object($file_name) {
292292
if ($this->is_valid_file_object($file_name)) {
293-
$file = new stdClass();
293+
$file = new \stdClass();
294294
$file->name = $file_name;
295295
$file->size = $this->get_file_size(
296296
$this->get_upload_path($file_name)
@@ -391,7 +391,8 @@ protected function validate($uploaded_file, $file, $error, $index) {
391391
$max_height = @$this->options['max_height'];
392392
$min_width = @$this->options['min_width'];
393393
$min_height = @$this->options['min_height'];
394-
if (($max_width || $max_height || $min_width || $min_height)) {
394+
if (($max_width || $max_height || $min_width || $min_height)
395+
&& preg_match($this->options['image_file_types'], $file->name)) {
395396
list($img_width, $img_height) = $this->get_image_size($uploaded_file);
396397
}
397398
if (!empty($img_width)) {
@@ -751,7 +752,7 @@ protected function gd_create_scaled_image($file_name, $version, $options) {
751752
protected function imagick_get_image_object($file_path, $no_cache = false) {
752753
if (empty($this->image_objects[$file_path]) || $no_cache) {
753754
$this->imagick_destroy_image_object($file_path);
754-
$image = new Imagick();
755+
$image = new \Imagick();
755756
if (!empty($this->options['imagick_resource_limits'])) {
756757
foreach ($this->options['imagick_resource_limits'] as $type => $limit) {
757758
$image->setResourceLimit($type, $limit);
@@ -775,35 +776,35 @@ protected function imagick_destroy_image_object($file_path) {
775776

776777
protected function imagick_orient_image($image) {
777778
$orientation = $image->getImageOrientation();
778-
$background = new ImagickPixel('none');
779+
$background = new \ImagickPixel('none');
779780
switch ($orientation) {
780-
case imagick::ORIENTATION_TOPRIGHT: // 2
781+
case \imagick::ORIENTATION_TOPRIGHT: // 2
781782
$image->flopImage(); // horizontal flop around y-axis
782783
break;
783-
case imagick::ORIENTATION_BOTTOMRIGHT: // 3
784+
case \imagick::ORIENTATION_BOTTOMRIGHT: // 3
784785
$image->rotateImage($background, 180);
785786
break;
786-
case imagick::ORIENTATION_BOTTOMLEFT: // 4
787+
case \imagick::ORIENTATION_BOTTOMLEFT: // 4
787788
$image->flipImage(); // vertical flip around x-axis
788789
break;
789-
case imagick::ORIENTATION_LEFTTOP: // 5
790+
case \imagick::ORIENTATION_LEFTTOP: // 5
790791
$image->flopImage(); // horizontal flop around y-axis
791792
$image->rotateImage($background, 270);
792793
break;
793-
case imagick::ORIENTATION_RIGHTTOP: // 6
794+
case \imagick::ORIENTATION_RIGHTTOP: // 6
794795
$image->rotateImage($background, 90);
795796
break;
796-
case imagick::ORIENTATION_RIGHTBOTTOM: // 7
797+
case \imagick::ORIENTATION_RIGHTBOTTOM: // 7
797798
$image->flipImage(); // vertical flip around x-axis
798799
$image->rotateImage($background, 270);
799800
break;
800-
case imagick::ORIENTATION_LEFTBOTTOM: // 8
801+
case \imagick::ORIENTATION_LEFTBOTTOM: // 8
801802
$image->rotateImage($background, 270);
802803
break;
803804
default:
804805
return false;
805806
}
806-
$image->setImageOrientation(imagick::ORIENTATION_TOPLEFT); // 1
807+
$image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT); // 1
807808
return true;
808809
}
809810

@@ -856,7 +857,7 @@ protected function imagick_create_scaled_image($file_name, $version, $options) {
856857
$success = $image->resizeImage(
857858
$new_width,
858859
$new_height,
859-
isset($options['filter']) ? $options['filter'] : imagick::FILTER_LANCZOS,
860+
isset($options['filter']) ? $options['filter'] : \imagick::FILTER_LANCZOS,
860861
isset($options['blur']) ? $options['blur'] : 1,
861862
$new_width && $new_height // fit image into constraints if not to be cropped
862863
);
@@ -876,7 +877,7 @@ protected function imagick_create_scaled_image($file_name, $version, $options) {
876877
case 'jpg':
877878
case 'jpeg':
878879
if (!empty($options['jpeg_quality'])) {
879-
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
880+
$image->setImageCompression(\imagick::COMPRESSION_JPEG);
880881
$image->setImageCompressionQuality($options['jpeg_quality']);
881882
}
882883
break;
@@ -891,7 +892,7 @@ protected function imagemagick_create_scaled_image($file_name, $version, $option
891892
list($file_path, $new_file_path) =
892893
$this->get_scaled_image_file_paths($file_name, $version);
893894
$resize = @$options['max_width']
894-
.(empty($options['max_height']) ? '' : 'x'.$options['max_height']);
895+
.(empty($options['max_height']) ? '' : 'X'.$options['max_height']);
895896
if (!$resize && empty($options['auto_orient'])) {
896897
if ($file_path !== $new_file_path) {
897898
return copy($file_path, $new_file_path);
@@ -934,7 +935,7 @@ protected function imagemagick_create_scaled_image($file_name, $version, $option
934935
protected function get_image_size($file_path) {
935936
if ($this->options['image_library']) {
936937
if (extension_loaded('imagick')) {
937-
$image = new Imagick();
938+
$image = new \Imagick();
938939
try {
939940
if (@$image->pingImage($file_path)) {
940941
$dimensions = array($image->getImageWidth(), $image->getImageHeight());
@@ -1019,7 +1020,7 @@ protected function handle_image_file($file_path, $file) {
10191020

10201021
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
10211022
$index = null, $content_range = null) {
1022-
$file = new stdClass();
1023+
$file = new \stdClass();
10231024
$file->name = $this->get_file_name($uploaded_file, $name, $size, $type, $error,
10241025
$index, $content_range);
10251026
$file->size = $this->fix_integer_overflow(intval($size));

0 commit comments

Comments
 (0)