diff options
| author | Savetheinternet <savetheinternet@tinyboard.org> | 2011-08-24 18:22:07 +1000 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@tinyboard.org> | 2011-08-24 18:22:07 +1000 |
| commit | 881ea101628ec03a199b87dafd6a560a69e6901e (patch) | |
| tree | 7ba9c29f8174d34b4cf26f176be397ffbe1c9703 /post.php | |
| parent | 087e41c48a53e4e6892cd327a3b8598777b62608 (diff) | |
find image size before loading image into memory
Diffstat (limited to 'post.php')
| -rw-r--r-- | post.php | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -431,6 +431,40 @@ } require_once 'inc/image.php'; + + if($config['imagick']) { + // This is tricky, because Imagick won't let us find + // an image's dimensions without loading it all into + // memory first, unlike GD which provides the + // getimagesize() to do exactly that. This section + // is why GD is required, even when using Imagick + // instead. There doesn't seem to be an alternative. + // Necessary for security, as Imagick even ignores + // PHP's memory limit. + + // first try GD's getimagesize() + if($size = @getimagesize($post['file'])) { + if($size[0] > $config['max_width'] || $size[1] > $config['max_height']) { + file_unlink($post['file']); + error($config['error']['maxsize']); + } + } else { + // GD failed + // TODO? + } + } else { + // find dimensions of an image using GD + if(!$size = @getimagesize($post['file'])) { + file_unlink($post['file']); + error($config['error']['invalidimg']); + } + if($size[0] > $config['max_width'] || $size[1] > $config['max_height']) { + file_unlink($post['file']); + error($config['error']['maxsize']); + } + } + + // create image object $image = new Image($post['file'], $post['extension']); |
