From d9964ef61832a507ed78a0e4bf4208700cb16f9f Mon Sep 17 00:00:00 2001 From: Greg Froese Date: Mon, 11 May 2009 05:44:02 +0000 Subject: imagemagick support for creating thumbnails and watermarking --- actions/resize.php | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 actions/resize.php (limited to 'actions/resize.php') diff --git a/actions/resize.php b/actions/resize.php new file mode 100644 index 000000000..8a8a5bb34 --- /dev/null +++ b/actions/resize.php @@ -0,0 +1,109 @@ +$input_name, + "output_name"=>$output_name, + "maxwidth"=>$maxwidth, + "maxheight"=>$maxheight, + "square"=>$square, + "x1"=>$x1, + "y1"=>$y1, + "x2"=>$x2, + "y2"=>$y2); + + $path = pathinfo($input_name); + $output_name = $path["dirname"] . "/$prefix" . $path["filename"] . "." . $path["extension"]; + + // Get the size information from the image + if ($imgsizearray = getimagesize($input_name)) { + + // Get width and height + $width = $imgsizearray[0]; + $height = $imgsizearray[1]; + $newwidth = $width; + $newheight = $height; + + // Square the image dimensions if we're wanting a square image + if ($square) { + if ($width < $height) { + $height = $width; + } else { + $width = $height; + } + + $newwidth = $width; + $newheight = $height; + + } + + if ($width > $maxwidth) { + $newheight = floor($height * ($maxwidth / $width)); + $newwidth = $maxwidth; + } + if ($newheight > $maxheight) { + $newwidth = floor($newwidth * ($maxheight / $newheight)); + $newheight = $maxheight; + } + + $accepted_formats = array( + 'image/jpeg' => 'jpeg', + 'image/png' => 'png', + 'image/gif' => 'gif' + ); + // If it's a file we can manipulate ... + if (array_key_exists($imgsizearray['mime'],$accepted_formats)) { + +// $function = "imagecreatefrom" . $accepted_formats[$imgsizearray['mime']]; +// $newimage = imagecreatetruecolor($newwidth,$newheight); + +// if (is_callable($function) && $oldimage = $function($input_name)) { + // Crop the image if we need a square + if ($square) { + if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) { + $widthoffset = floor(($imgsizearray[0] - $width) / 2); + $heightoffset = floor(($imgsizearray[1] - $height) / 2); + } else { + $widthoffset = $x1; + $heightoffset = $y1; + $width = ($x2 - $x1); + $height = $width; + } + } else { + if ($x1 == 0 && $y1 == 0 && $x2 == 0 && $y2 ==0) { + $widthoffset = 0; + $heightoffset = 0; + } else { + $widthoffset = $x1; + $heightoffset = $y1; + $width = ($x2 - $x1); + $height = ($y2 - $y1); + } + }//else { + // Resize and return the image contents! + if ($square) { + $newheight = $maxheight; + $newwidth = $maxwidth; + } + $command = "convert $input_name -resize ".$newwidth."x".$newheight."^ -gravity center -extent ".$newwidth."x".$newheight." $output_name"; + system($command); + return $output_name; + + } + } + + return false; + } + +?> -- cgit v1.2.3