[limb-svn] r6308 - 3.x/trunk/limb/imagekit/src
svn at limb-project.com
svn at limb-project.com
Mon Sep 17 15:35:35 MSD 2007
Author: serega
Date: 2007-09-17 15:35:35 +0400 (Mon, 17 Sep 2007)
New Revision: 6308
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6308
Added:
3.x/trunk/limb/imagekit/src/lmbImageResizer.class.php
Log:
-- lmbImageResizer.class.php added
Added: 3.x/trunk/limb/imagekit/src/lmbImageResizer.class.php
===================================================================
--- 3.x/trunk/limb/imagekit/src/lmbImageResizer.class.php (rev 0)
+++ 3.x/trunk/limb/imagekit/src/lmbImageResizer.class.php 2007-09-17 11:35:35 UTC (rev 6308)
@@ -0,0 +1,84 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+
+lmb_require('limb/imagekit/src/lmbImageFactory.class.php');
+lmb_require('limb/net/src/lmbMimeType.class.php');
+/**
+ * class lmbImage
+ *
+ * @package imagekit
+ * @version $Id$
+ */
+class lmbImageResizer
+{
+ protected $filename;
+ protected $mime_type;
+
+ function __construct($filepath, $mime_type = null)
+ {
+ $this->filepath = $filepath;
+
+ if($mime_type)
+ $this->mime_type = $mime_type;
+ else
+ $this->mime_type = lmbMimeType :: getFileMimeType($filepath);
+ }
+
+ function getFilePath()
+ {
+ return $this->filepath;
+ }
+
+ function getMimeType()
+ {
+ return $this->mime_type;
+ }
+
+ function resize($max_size)
+ {
+ $input_file = $this->getFilePath();
+ $tmp_file = lmbFs :: generateTmpFile();
+
+ try
+ {
+ $image_library = lmbImageFactory :: create();
+
+ $input_file_type = $image_library->getImageType($this->getMimeType());
+ $output_file_type = $image_library->fallBackToAnySupportedType($input_file_type);
+
+ $output_file = $tmp_file . '.' . $output_file_type;
+
+ $image_library->setInputFile($input_file);
+ $image_library->setInputType($input_file_type);
+
+ $image_library->setOutputFile($output_file);
+ $image_library->setOutputType($output_file_type);
+
+ $image_library->resize(array('max_dimension' => $max_size));
+ $image_library->commit();
+ }
+ catch(lmbException $e)
+ {
+ if(file_exists($output_file))
+ unlink($output_file);
+
+ throw $e;
+ }
+
+ $this->filepath = $output_file;
+ return $output_file;
+ }
+
+ function cleanup()
+ {
+ if(file_exists($this->filepath))
+ unlink($this->filepath);
+ }
+}
+?>
\ No newline at end of file
More information about the limb-svn
mailing list