From 5614a7f7daa4edffbcc7a1dfbae56c97c8f5e803 Mon Sep 17 00:00:00 2001 From: shish Date: Wed, 25 Apr 2007 18:33:59 +0000 Subject: [PATCH] less duplication again git-svn-id: file:///home/shish/svn/shimmie2/trunk@14 7f39781d-f577-437e-ae19-be835c7a54ca --- core/ext/image.ext.php | 23 ++++++----------------- core/util.inc.php | 15 +++++++++++++++ ext/regen_thumb.ext.php | 23 ++++++----------------- 3 files changed, 27 insertions(+), 34 deletions(-) diff --git a/core/ext/image.ext.php b/core/ext/image.ext.php index fc37a8fe..d5027758 100644 --- a/core/ext/image.ext.php +++ b/core/ext/image.ext.php @@ -113,9 +113,6 @@ class ImageIO extends Extension { $width = $info[0]; $height = $info[1]; - $max_width = $config->get_int('thumb_width'); - $max_height = $config->get_int('thumb_height'); - $memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024); $memory_limit = get_memory_limit(); @@ -129,21 +126,13 @@ class ImageIO extends Extension { } else { $image = imagecreatefromstring($this->read_file($tmpname)); + $tsize = get_thumbnail_size($width, $height); - $xscale = ($max_height / $height); - $yscale = ($max_width / $width); - $scale = ($xscale < $yscale) ? $xscale : $yscale; - - if($scale >= 1) { - $thumb = $image; - } - else { - $thumb = imagecreatetruecolor($width*$scale, $height*$scale); - imagecopyresampled( - $thumb, $image, 0, 0, 0, 0, - $width*$scale, $height*$scale, $width, $height - ); - } + $thumb = imagecreatetruecolor($tsize[0], $tsize[1]); + imagecopyresampled( + $thumb, $image, 0, 0, 0, 0, + $tsize[0], $tsize[1], $width, $height + ); return $thumb; } } diff --git a/core/util.inc.php b/core/util.inc.php index 2dffdd60..c15f3ed9 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -125,7 +125,22 @@ function tag_explode($tags) { } +function get_thumbnail_size($orig_width, $orig_height) { + global $config; + $max_width = $config->get_int('thumb_width'); + $max_height = $config->get_int('thumb_height'); + $xscale = ($max_height / $orig_height); + $yscale = ($max_width / $orig_width); + $scale = ($xscale < $yscale) ? $xscale : $yscale; + +// if($scale >= 1) { +// return array($orig_width, $orig_height); +// } +// else { + return array($orig_width*$scale, $orig_height*$scale); +// } +} # $db is the connection object diff --git a/ext/regen_thumb.ext.php b/ext/regen_thumb.ext.php index 8a5ebc7d..58118672 100644 --- a/ext/regen_thumb.ext.php +++ b/ext/regen_thumb.ext.php @@ -90,9 +90,6 @@ class RegenThumb extends Extension { $width = $info[0]; $height = $info[1]; - $max_width = $config->get_int('thumb_width'); - $max_height = $config->get_int('thumb_height'); - $memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024); $memory_limit = get_memory_limit(); @@ -106,21 +103,13 @@ class RegenThumb extends Extension { } else { $image = imagecreatefromstring($this->read_file($tmpname)); + $tsize = get_thumbnail_size($width, $height); - $xscale = ($max_height / $height); - $yscale = ($max_width / $width); - $scale = ($xscale < $yscale) ? $xscale : $yscale; - - if($scale >= 1) { - $thumb = $image; - } - else { - $thumb = imagecreatetruecolor($width*$scale, $height*$scale); - imagecopyresampled( - $thumb, $image, 0, 0, 0, 0, - $width*$scale, $height*$scale, $width, $height - ); - } + $thumb = imagecreatetruecolor($tsize[0], $tsize[1]); + imagecopyresampled( + $thumb, $image, 0, 0, 0, 0, + $tsize[0], $tsize[1], $width, $height + ); return $thumb; } }