1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 21:57:51 +02:00

Bugtracker #3872 - change quotes for Windows, tidy up

This commit is contained in:
e107steved
2007-04-13 21:45:46 +00:00
parent 4d6c749bd7
commit a08cdf4270

View File

@@ -11,145 +11,177 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_handlers/resize_handler.php,v $ | $Source: /cvs_backup/e107_0.8/e107_handlers/resize_handler.php,v $
| $Revision: 1.1.1.1 $ | $Revision: 1.2 $
| $Date: 2006-12-02 04:33:57 $ | $Date: 2007-04-13 21:45:38 $
| $Author: mcfly_e107 $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
if (!defined('e107_INIT')) { exit; } if (!defined('e107_INIT')) { exit; }
/* 07-04-2004 - unknown: removed source/destination file rewriting, this should not break existing code */ function resize_image($source_file, $destination_file, $type = "upload", $model = "")
/* 09-04-2004 - unknown: source/destination file should be quoted, otherwise files with spaces can't be handled */ {
function resize_image($source_file, $destination_file, $type = "upload", $model = "") { // $destination_file - 'stdout' sends direct to browser. Otherwise treated as file name
// $type - "upload"
// - numeric - sets new width of image
// - anything else - default preference for image width used, or failing that, 120 pixels
// $model - if "copy", creates a new file with the prefix 'thumb_'. Otherwise overwrites
global $pref; global $pref;
$new_height = 0; $new_height = 0;
$mode = ($pref['resize_method'] ? $pref['resize_method'] : "gd2"); $mode = ($pref['resize_method'] ? $pref['resize_method'] : "gd2");
if ($type == "upload") { if ($type == "upload")
$new_size = ($pref['im_width'] ? $pref['im_width'] : 400); {
$new_size = ($pref['im_width'] ? $pref['im_width'] : 400);
} }
else if(is_numeric($type)) { elseif(is_numeric($type))
$new_size = $type; {
} else { $new_size = $type;
$new_size = ($pref['im_width'] ? $pref['im_width'] : 120); }
//avatar else
$new_height = ($pref['im_height'] ? $pref['im_height'] : 100); { // Use preferences or failing that hard-coded defaults for new size
//avatar $new_size = ($pref['im_width'] ? $pref['im_width'] : 120);
$new_height = ($pref['im_height'] ? $pref['im_height'] : 100);
} }
$im_quality = ($pref['im_quality'] ? $pref['im_quality'] : 99); $im_quality = ($pref['im_quality'] ? $pref['im_quality'] : 99);
$image_stats = getimagesize($source_file); $image_stats = getimagesize($source_file);
/*
if ($image_stats[0] <= $type && is_numeric($type)) { if ($image_stats[0] <= $type && is_numeric($type))
return false; {
return false;
}
*/
if ($image_stats == null)
{
echo "<b>DEBUG</b> image_stats are null<br />";
return false;
} }
if ($image_stats == null) { // Check the image type. '2'=jpeg
echo "<b>DEBUG</b> image_stats are null<br />"; if ($image_stats[2] != 1 && $image_stats[2] != 2 && $image_stats[2] != 3 && ($mode == 'gd1' || $mode == 'gd2'))
return false; {
echo "<b>DEBUG</b> Wrong image type<br />";
return FALSE;
}
$imagewidth = $image_stats[0]; // Width of existing image
$imageheight = $image_stats[1]; // Height of existing image
if ($imagewidth <= $new_size && ($imageheight <= $new_height || $new_height == 0))
{ // Nothing to do if image width already smaller than the maximum
return TRUE;
} }
if ($image_stats[2] != 1 && $image_stats[2] != 2 && $image_stats[2] != 3 && ($mode == 'gd1' || $mode == 'gd2')) {
echo "<b>DEBUG</b> Wrong image type<br />";
return FALSE;
}
$imagewidth = $image_stats[0];
$imageheight = $image_stats[1];
if ($imagewidth <= $new_size && ($imageheight <= $new_height || $new_height == 0)) {
return TRUE;
}
$ratio = ($imagewidth / $new_size); $ratio = ($imagewidth / $new_size);
$new_imageheight = round($imageheight / $ratio); $new_imageheight = round($imageheight / $ratio);
if (($new_height <= $new_imageheight) && $new_height > 0) { if (($new_height <= $new_imageheight) && $new_height > 0)
{
$ratio = $new_imageheight / $new_height; $ratio = $new_imageheight / $new_height;
$new_imageheight = $new_height; $new_imageheight = $new_height;
$new_size = round($new_size / $ratio); $new_size = round($new_size / $ratio);
} }
if ($mode == "ImageMagick") {
if ($destination_file == "stdout") {
/* if destination is stdout, output directly to the browser */
$destination_file = "jpg:-";
header("Content-type: image/jpeg");
passthru ($pref['im_path']."convert -quality ".$im_quality." -antialias -geometry ".$new_size."x".$new_imageheight." ".escapeshellarg($source_file)." '".$destination_file."'");
} else {
/* otherwise output to file */
if ($model == "copy") {
$name = substr($destination_file, (strrpos($destination_file, "/")+1));
$name2 = "thumb_".$name;
$destination_file = str_replace($name, $name2, $destination_file);
}
exec ($pref['im_path']."convert -quality ".$im_quality." -antialias -geometry ".$new_size."x".$new_imageheight." ".escapeshellarg($source_file)." '".$destination_file."'");
switch ($mode)
{
case "ImageMagick" :
if ($destination_file == "stdout")
{ /* if destination is stdout, output directly to the browser */
// $destination_file = "jpg:-";
header("Content-type: image/jpeg");
// Use double quotes instead of single to keep Bill happy
passthru ($pref['im_path']."convert -quality ".$im_quality." -antialias -geometry ".$new_size."x".$new_imageheight." ".escapeshellarg($source_file)." \"jpg:-\"");
} }
}
else if($mode == "gd1") {
if ($image_stats[2] == 2)
$src_img = imagecreatefromjpeg($source_file);
else else
$src_img = imagecreatefrompng($source_file); { /* otherwise output to file */
if (!$src_img) { if ($model == "copy")
return FALSE; {
}
$dst_img = imagecreate($new_size, $new_imageheight);
imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $new_size, $new_imageheight, $imagewidth, $imageheight);
if ($model == "copy") {
$name = substr($destination_file, (strrpos($destination_file, "/")+1)); $name = substr($destination_file, (strrpos($destination_file, "/")+1));
$name2 = "thumb_".$name; $name2 = "thumb_".$name;
$destination_file = str_replace($name, $name2, $destination_file); $destination_file = str_replace($name, $name2, $destination_file);
}
// Use double quotes instead of single to keep Bill happy
// exec ($pref['im_path']."convert -quality ".$im_quality." -antialias -geometry ".$new_size."x".$new_imageheight." ".escapeshellarg($source_file)." '".$destination_file."'");
exec ($pref['im_path']."convert -quality ".$im_quality." -antialias -geometry ".$new_size."x".$new_imageheight." ".escapeshellarg($source_file)." \"".$destination_file."\"");
}
case "gd1" :
if ($image_stats[2] == 2)
$src_img = imagecreatefromjpeg($source_file);
else
$src_img = imagecreatefrompng($source_file);
if (!$src_img)
{
return FALSE;
}
$dst_img = imagecreate($new_size, $new_imageheight); // Create blank image of correct size as target
// Only next line is different between gd1 and gd2
imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $new_size, $new_imageheight, $imagewidth, $imageheight);
if ($model == "copy")
{
$name = substr($destination_file, (strrpos($destination_file, "/")+1));
$name2 = "thumb_".$name;
$destination_file = str_replace($name, $name2, $destination_file);
} }
if ($destination_file == "stdout") { if ($destination_file == "stdout")
header("Content-type: image/jpeg"); {
imagejpeg($dst_img, '', $im_quality); header("Content-type: image/jpeg");
} else { imagejpeg($dst_img, '', $im_quality);
imagejpeg($dst_img, $destination_file, $im_quality);
imagedestroy($src_img);
imagedestroy($dst_img);
} }
else
} {
else if($mode == "gd2") { imagejpeg($dst_img, $destination_file, $im_quality);
imagedestroy($src_img);
imagedestroy($dst_img);
}
case "gd2" :
if ($image_stats[2] == 2) if ($image_stats[2] == 2)
$src_img = imagecreatefromjpeg($source_file); $src_img = imagecreatefromjpeg($source_file);
else else
$src_img = imagecreatefrompng($source_file); $src_img = imagecreatefrompng($source_file);
if (!$src_img) { if (!$src_img)
return FALSE; {
return FALSE;
} }
$dst_img = imagecreatetruecolor($new_size, $new_imageheight); $dst_img = imagecreatetruecolor($new_size, $new_imageheight);
// Only next line is different between gd1 and gd2
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_size, $new_imageheight, $imagewidth, $imageheight); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_size, $new_imageheight, $imagewidth, $imageheight);
if ($model == "copy")
{
$name = substr($destination_file, (strrpos($destination_file, "/")+1));
$name2 = "thumb_".$name;
$destination_file = str_replace($name, $name2, $destination_file);
}
if ($model == "copy") { if ($destination_file == "stdout")
$name = substr($destination_file, (strrpos($destination_file, "/")+1)); {
$name2 = "thumb_".$name; header("Content-type: image/jpeg");
$destination_file = str_replace($name, $name2, $destination_file); imagejpeg($dst_img, '', $im_quality);
} }
if ($destination_file == "stdout") { else
header("Content-type: image/jpeg"); {
imagejpeg($dst_img, '', $im_quality); imagejpeg($dst_img, $destination_file, $im_quality);
} else { imagedestroy($src_img);
imagejpeg($dst_img, $destination_file, $im_quality); imagedestroy($dst_img);
imagedestroy($src_img);
imagedestroy($dst_img);
} }
} } // End switch($mode)
if ($destination_file == "stdout") return TRUE; // Can't do anything more if file sent to stdout - assume success
@chmod($destination_file, 0644); @chmod($destination_file, 0644);
if ($pref['image_owner']) { if ($pref['image_owner'])
@chown($destination_file, $pref['image_owner']); {
@chown($destination_file, $pref['image_owner']);
} }
$image_stats = getimagesize($destination_file); $image_stats = getimagesize($destination_file);
if ($image_stats == null) { if ($image_stats == null)
// @unlink($source_file); {
return FALSE; return FALSE;
} else { }
return TRUE; else
{
return TRUE;
} }
} }
?> ?>