Skip to content

Commit c11278a

Browse files
committed
Added option to set imagick resource limits.
Destroy old image objects in gd_set_image_object method.
1 parent ba3eec2 commit c11278a

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

server/php/UploadHandler.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* jQuery File Upload Plugin PHP Class 6.10.0
3+
* jQuery File Upload Plugin PHP Class 6.11.0
44
* https://github.com/blueimp/jQuery-File-Upload
55
*
66
* Copyright 2010, Sebastian Tschan
@@ -94,9 +94,14 @@ function __construct($options = null, $initialize = true, $error_messages = null
9494
'min_height' => 1,
9595
// Set the following option to false to enable resumable uploads:
9696
'discard_aborted_uploads' => true,
97-
// Set to 0 to use the GD image extension to scale and orient images
98-
// instead of imagick, which is used by default if installed:
97+
// Set to 0 to use the GD library to scale and orient images,
98+
// set to 1 to use imagick (if installed, falls back to GD):
9999
'image_library' => 1,
100+
// Define an array of resource limits for imagick:
101+
'imagick_resource_limits' => array(
102+
//imagick::RESOURCETYPE_MAP => 32,
103+
//imagick::RESOURCETYPE_MEMORY => 32
104+
),
100105
// Set to false to disable rotating images based on EXIF meta data:
101106
'orient_image' => true,
102107
'image_versions' => array(
@@ -479,6 +484,7 @@ protected function gd_get_image_object($file_path, $func, $no_cache = false) {
479484
}
480485

481486
protected function gd_set_image_object($file_path, $image) {
487+
$this->gd_destroy_image_object($file_path);
482488
$this->image_objects[$file_path] = $image;
483489
}
484490

@@ -577,8 +583,6 @@ protected function gd_create_scaled_image($file_name, $version, $options) {
577583
$img_height
578584
) && $write_func($new_img, $new_file_path, $image_quality);
579585
$this->gd_set_image_object($file_path, $new_img);
580-
// Free up memory (imagedestroy does not delete files):
581-
imagedestroy($src_img);
582586
return $success;
583587
}
584588

@@ -659,6 +663,7 @@ protected function gd_orient_image($file_path) {
659663
defined('IMG_FLIP_HORIZONTAL') ? IMG_FLIP_HORIZONTAL : 1
660664
);
661665
$new_img = imagerotate($tmp_img, 270, 0);
666+
imagedestroy($tmp_img);
662667
break;
663668
case 6:
664669
$new_img = imagerotate($src_img, 270, 0);
@@ -669,6 +674,7 @@ protected function gd_orient_image($file_path) {
669674
defined('IMG_FLIP_VERTICAL') ? IMG_FLIP_VERTICAL : 2
670675
);
671676
$new_img = imagerotate($tmp_img, 270, 0);
677+
imagedestroy($tmp_img);
672678
break;
673679
case 8:
674680
$new_img = imagerotate($src_img, 90, 0);
@@ -677,16 +683,19 @@ protected function gd_orient_image($file_path) {
677683
return false;
678684
}
679685
$this->gd_set_image_object($file_path, $new_img);
680-
// Free up memory (imagedestroy does not delete files):
681-
@imagedestroy($tmp_img);
682-
imagedestroy($src_img);
683686
return imagejpeg($new_img, $file_path);
684687
}
685688

686689
protected function imagick_get_image_object($file_path, $no_cache = false) {
687690
if (empty($this->image_objects[$file_path]) || $no_cache) {
688691
$this->imagick_destroy_image_object($file_path);
689-
$this->image_objects[$file_path] = new Imagick($file_path);
692+
$image = new Imagick($file_path);
693+
if (!empty($this->options['imagick_resource_limits'])) {
694+
foreach ($this->options['imagick_resource_limits'] as $type => $limit) {
695+
$image->setResourceLimit($type, $limit);
696+
}
697+
}
698+
$this->image_objects[$file_path] = $image;
690699
}
691700
return $this->image_objects[$file_path];
692701
}

0 commit comments

Comments
 (0)