diff options
| author | Savetheinternet <savetheinternet@tinyboard.org> | 2011-07-12 20:29:35 +1000 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@tinyboard.org> | 2011-07-12 20:29:35 +1000 |
| commit | 97979b79992474d342404f76a61936c456c0565d (patch) | |
| tree | ac564e784aaf18a6d3bc4da7711c192b48e80ef3 /post.php | |
| parent | 2d00b32bede669d82b09f3a1c78923883581bff2 (diff) | |
image handling class
Diffstat (limited to 'post.php')
| -rw-r--r-- | post.php | 49 |
1 files changed, 26 insertions, 23 deletions
@@ -431,21 +431,6 @@ if(!@move_uploaded_file($_FILES['file']['tmp_name'], $post['file'])) error($config['error']['nomove']); if(!isset($__file)) { - $size = @getimagesize($post['file']); - $post['width'] = &$size[0]; - $post['height'] = &$size[1]; - - // Check if the image is valid - if($post['width'] < 1 || $post['height'] < 1) { - undoImage($post); - error($config['error']['invalidimg']); - } - - if($post['width'] > $config['max_width'] || $post['height'] > $config['max_height']) { - undoImage($post); - error($config['error']['maxsize']); - } - // Check IE MIME type detection XSS exploit $buffer = file_get_contents($post['file'], null, null, null, 255); if(preg_match($config['ie_mime_type_detection'], $buffer)) { @@ -453,21 +438,39 @@ error($config['error']['mime_exploit']); } - if($config['minimum_copy_resize'] && $post['width'] <= $config['thumb_width'] && $post['height'] <= $config['thumb_height'] && $post['extension'] == ($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension'])) { + require_once 'inc/image.php'; + // create image object + $image = new Image($post['file'], $post['extension']); + + if($image->size->width > $config['max_width'] || $image->size->height > $config['max_height']) { + $image->delete(); + error($config['error']['maxsize']); + } + + + if($config['minimum_copy_resize'] && + $image->size->width <= $config['thumb_width'] && + $image->size->height <= $config['thumb_height'] && + $post['extension'] == ($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension'])) { + // Copy, because there's nothing to resize copy($post['file'], $post['thumb']); - $post['thumbwidth'] = $post['width']; - $post['thumbheight'] = $post['height']; + $post['thumbwidth'] = $image->size->width; + $post['thumbheight'] = $image->size->height; } else { - $image = createimage($post['extension'], $post['file']); + $thumb = $image->resize($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension'], $config['thumb_width'], $config['thumb_height']); + $thumb->to($post['thumb']); - // Create a thumbnail - $thumb = resize($image, $post['width'], $post['height'], $post['thumb'], $config['thumb_width'], $config['thumb_height'], ($config['thumb_ext'] ? $config['thumb_ext'] : $post['extension'])); + //header('Content-Type: text/plain'); + //var_dump($thumb); + //exit; - $post['thumbwidth'] = $thumb['width']; - $post['thumbheight'] = $thumb['height']; + $post['thumbwidth'] = $thumb->width; + $post['thumbheight'] = $thumb->height; + $thumb->_destroy(); } + $image->destroy(); } else { copy($config['file_thumb'], $post['thumb']); |
