aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2009-05-17 17:45:58 +0000
committerCash Costello <cash.costello@gmail.com>2009-05-17 17:45:58 +0000
commit47a49c851ab285e7e4f48aa29247a8a71fdb9d5c (patch)
tree828eb5e03395149504b35f618ebdcce263c3a441
parent7e09496c62e79eaaadbfdd2ee8b83602fde50497 (diff)
downloadelgg-47a49c851ab285e7e4f48aa29247a8a71fdb9d5c.tar.gz
elgg-47a49c851ab285e7e4f48aa29247a8a71fdb9d5c.tar.bz2
moved all resize code into lib/resize.php
-rw-r--r--actions/resize.php111
-rw-r--r--actions/upload.php50
-rw-r--r--lib/resize.php166
3 files changed, 168 insertions, 159 deletions
diff --git a/actions/resize.php b/actions/resize.php
deleted file mode 100644
index bcb2ba520..000000000
--- a/actions/resize.php
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-
-/*
- * Gets the jpeg contents of the resized version of an already uploaded image
- * (Returns false if the uploaded file was not an image)
- *
- * @param string $input_name The name of the file input field on the submission form
- * @param string $prefix The text to prefix to the existing filename
- * @param int $maxwidth The maximum width of the resized image
- * @param int $maxheight The maximum height of the resized image
- * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.
- * @return false|mixed The contents of the resized image, or false on failure
- */
- function tp_resize($input_name, $prefix, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {
- $params = array(
- "input_name"=>$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)) {
-
- // 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);
- }
- }
-
- // Resize and return the image contents!
- if ($square) {
- $newheight = $maxheight;
- $newwidth = $maxwidth;
- }
- $im_path = get_plugin_setting('convert_command', 'tidypics');
- if(!$im_path) {
- $im_path = "/usr/bin/";
- }
- if(substr($im_path, strlen($im_path)-1, 1) != "/") $im_path .= "/";
- $command = $im_path . "convert \"$input_name\" -resize ".$newwidth."x".$newheight."^ -gravity center -extent ".$newwidth."x".$newheight." \"$output_name\"";
- system($command);
- return $output_name;
-
- }
- }
-
- return false;
- }
-
-?>
diff --git a/actions/upload.php b/actions/upload.php
index ecdeb27f7..7c50b95d4 100644
--- a/actions/upload.php
+++ b/actions/upload.php
@@ -6,7 +6,6 @@
*/
global $CONFIG;
- include dirname(__FILE__) . "/resize.php";
include dirname(dirname(__FILE__)) . "/lib/resize.php";
// Get common variables
@@ -138,60 +137,15 @@
*/
} else { // ImageMagick command line
-/*
+
if (tp_create_imagick_cmdline_thumbnails($file, $prefix, $filestorename) != true) {
trigger_error('Tidypics warning: failed to create thumbnails', E_USER_WARNING);
}
-*/
- //gfroese: build the actual thumbnails now
$album = get_entity($container_guid);
$user = get_user_entity_as_row($album->owner_guid);
$username = $user->username;
-
- try {
- $thumblarge = tp_resize($file->getFilenameOnFilestore(),
- "largethumb",
- $CONFIG->tidypics->image_large_width,
- $CONFIG->tidypics->image_large_height,
- false);
- } catch (Exception $e) { $thumblarge = false; }
- try {
- $thumbsmall = tp_resize($file->getFilenameOnFilestore(),
- "smallthumb",
- $CONFIG->tidypics->image_small_width,
- $CONFIG->tidypics->image_small_height,
- true);
- } catch (Exception $e) { $thumbsmall = false; }
- try {
- $thumbnail = tp_resize($file->getFilenameOnFilestore(),
- "thumb",
- $CONFIG->tidypics->image_thumb_width,
- $CONFIG->tidypics->image_thumb_height,
- true);
- } catch (Exception $e) { $thumbnail = false; }
-
- if ($thumbnail) {
- $thumb = new ElggFile();
- $thumb->setMimeType($mime);
- $thumb->setFilename($prefix."thumb".$filestorename);
- $file->thumbnail = $prefix."thumb".$filestorename;
- }
-
- if ($thumbsmall) {
- $thumb = new ElggFile();
- $thumb->setMimeType($mime);
- $thumb->setFilename($prefix."smallthumb".$filestorename);
- $file->smallthumb = $prefix."smallthumb".$filestorename;
- }
-
- if ($thumblarge) {
- $thumb = new ElggFile();
- $thumb->setMimeType($mime);
- $thumb->setFilename($prefix."largethumb".$filestorename);
- $file->largethumb = $prefix."largethumb".$filestorename;
- }
-
+
$im_path = get_plugin_setting('convert_command', 'tidypics');
if(!$im_path) {
$im_path = "/usr/bin/";
diff --git a/lib/resize.php b/lib/resize.php
index daf18efdf..bf63db82d 100644
--- a/lib/resize.php
+++ b/lib/resize.php
@@ -4,6 +4,7 @@
*
*/
+
/**
* Create thumbnails using PHP GD Library
*
@@ -82,5 +83,170 @@
return true;
}
+
+ /**
+ * Create thumbnails using ImageMagick executables
+ *
+ * @param ElggFile
+ * @param string
+ * @param string
+ * @return bool
+ */
+ function tp_create_imagick_cmdline_thumbnails($file, $prefix, $filestorename)
+ {
+ global $CONFIG;
+
+ $mime = $file->getMimeType();
+
+ $thumblarge = tp_imagick_resize($file->getFilenameOnFilestore(),
+ "largethumb",
+ $CONFIG->tidypics->image_large_width,
+ $CONFIG->tidypics->image_large_height,
+ false);
+
+ $thumbsmall = tp_imagick_resize($file->getFilenameOnFilestore(),
+ "smallthumb",
+ $CONFIG->tidypics->image_small_width,
+ $CONFIG->tidypics->image_small_height,
+ true);
+
+ $thumbnail = tp_imagick_resize($file->getFilenameOnFilestore(),
+ "thumb",
+ $CONFIG->tidypics->image_thumb_width,
+ $CONFIG->tidypics->image_thumb_height,
+ true);
+
+ if ($thumbnail) {
+ $thumb = new ElggFile();
+ $thumb->setMimeType($mime);
+ $thumb->setFilename($prefix."thumb".$filestorename);
+ $file->thumbnail = $prefix."thumb".$filestorename;
+ }
+
+ if ($thumbsmall) {
+ $thumb = new ElggFile();
+ $thumb->setMimeType($mime);
+ $thumb->setFilename($prefix."smallthumb".$filestorename);
+ $file->smallthumb = $prefix."smallthumb".$filestorename;
+ }
+
+ if ($thumblarge) {
+ $thumb = new ElggFile();
+ $thumb->setMimeType($mime);
+ $thumb->setFilename($prefix."largethumb".$filestorename);
+ $file->largethumb = $prefix."largethumb".$filestorename;
+ }
+
+ return true;
+ }
+
+ /*
+ * Gets the jpeg contents of the resized version of an already uploaded image
+ * (Returns false if the uploaded file was not an image)
+ *
+ * @param string $input_name The name of the file input field on the submission form
+ * @param string $prefix The text to prefix to the existing filename
+ * @param int $maxwidth The maximum width of the resized image
+ * @param int $maxheight The maximum height of the resized image
+ * @param true|false $square If set to true, will take the smallest of maxwidth and maxheight and use it to set the dimensions on all size; the image will be cropped.
+ * @return false|mixed The contents of the resized image, or false on failure
+ */
+ function tp_imagick_resize($input_name, $prefix, $maxwidth, $maxheight, $square = false, $x1 = 0, $y1 = 0, $x2 = 0, $y2 = 0) {
+
+ $params = array(
+ "input_name"=>$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)) {
+
+ // 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);
+ }
+ }
+
+ // Resize and return the image contents!
+ if ($square) {
+ $newheight = $maxheight;
+ $newwidth = $maxwidth;
+ }
+ $im_path = get_plugin_setting('convert_command', 'tidypics');
+ if(!$im_path) {
+ $im_path = "/usr/bin/";
+ }
+ if(substr($im_path, strlen($im_path)-1, 1) != "/") $im_path .= "/";
+ $command = $im_path . "convert \"$input_name\" -resize ".$newwidth."x".$newheight."^ -gravity center -extent ".$newwidth."x".$newheight." \"$output_name\"";
+ system($command);
+ return $output_name;
+
+ }
+ }
+
+ return false;
+ }
?> \ No newline at end of file