From fcd9762b51d26998445d7061261d18df70c8941c Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sun, 17 May 2009 02:28:58 +0000 Subject: moved code from upload action in resize library --- lib/resize.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'lib') diff --git a/lib/resize.php b/lib/resize.php index 657e56824..daf18efdf 100644 --- a/lib/resize.php +++ b/lib/resize.php @@ -4,5 +4,83 @@ * */ + /** + * Create thumbnails using PHP GD Library + * + * @param ElggFile + * @param string + * @param string + * @return bool + */ + function tp_create_gd_thumbnails($file, $prefix, $filestorename) + { + global $CONFIG; + + $mime = $file->getMimeType(); + + // Generate thumbnails + $thumbnail = get_resized_image_from_existing_file( $file->getFilenameOnFilestore(), + $CONFIG->tidypics->image_thumb_width, + $CONFIG->tidypics->image_thumb_height, + true); + + if ($thumbnail) { + $thumb = new ElggFile(); + $thumb->setMimeType($mime); + $thumb->setFilename($prefix."thumb".$filestorename); + $thumb->open("write"); + if ($thumb->write($thumbnail)) { + $file->thumbnail = $prefix."thumb".$filestorename; + } else { + $thumb->delete(); + } + $thumb->close(); + unset($thumb); + } + unset($thumbnail); + + $thumbsmall = get_resized_image_from_existing_file( $file->getFilenameOnFilestore(), + $CONFIG->tidypics->image_small_width, + $CONFIG->tidypics->image_small_height, + true); + + + if ($thumbsmall) { + $thumb = new ElggFile(); + $thumb->setMimeType($mime); + $thumb->setFilename($prefix."smallthumb".$filestorename); + $thumb->open("write"); + if ($thumb->write($thumbsmall)) { + $file->smallthumb = $prefix."smallthumb".$filestorename; + } else { + $thumb->delete(); + } + $thumb->close(); + unset($thumb); + } + unset($thumbsmall); + + $thumblarge = get_resized_image_from_existing_file( $file->getFilenameOnFilestore(), + $CONFIG->tidypics->image_large_width, + $CONFIG->tidypics->image_large_height, + false); + + if ($thumblarge) { + $thumb = new ElggFile(); + $thumb->setMimeType($mime); + $thumb->setFilename($prefix."largethumb".$filestorename); + $thumb->open("write"); + if ($thumb->write($thumblarge)) { + $file->largethumb = $prefix."largethumb".$filestorename; + } else { + $thumb->delete(); + } + $thumb->close(); + unset($thumb); + } + unset($thumblarge); + + return true; + } ?> \ No newline at end of file -- cgit v1.2.3