Source for file ImageFiles.class.php
Documentation is available at ImageFiles.class.php
* For including this file you have to define the constant "CLASSPATH".
* Because every include in the framework depends on the CLASSPATH definition.
* The CLASSPATH means the relative path to the folder that contains the
echo "<h3>You have to define the constant CLASSPATH!</h3>\r\n";
echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\r\n";
include_once( CLASSPATH. "filesystem/Files.class.php" );
* A class to manage image files in a filesystemtree.
* @author Daniel Plücken <daniel@debakel.net>
* @license http://www.gnu.org/copyleft/lesser.html
* GNU Lesser General Public License
* @copyright Copyright (c) 2005 Daniel Plücken <daniel@debakel.net>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
var $kind = ""; // JPG, PNG or GIF
* The jpeg quality from 0 to 100.
* @var string $jpeg_compression
* @author Daniel Plücken <daniel@debakel.net>
* @param string $path_or_width
* @param string $type_or_height
function ImageFiles( $path_or_width, $type_or_height = "" )
$this->Files( $path_or_width );
if ( preg_match( "!^(JPG|GIF|PNG)$!i", $type_or_height ) )
* Creates a handle to this image to be able to manipulate the image data. The
* handle will be stored in $this->handle.
* @author Daniel Plücken <daniel@debakel.net>
die ( "Not supported file format!" );
* Sets the comression quality for jpg between 0 (zero) and 100 (one hundred).
* @author Daniel Plücken <daniel@debakel.net>
* Sets the comression quality for jpg between 0 (zero) and 100 (one hundred).
* This method is an alias for the method setJPGCompression();
* @author Daniel Plücken <daniel@debakel.net>
* Scales the image to the given width and keeps the aspect ratio. Trys to
* preserve transparency info for GIFs & PNGs.
* @author Daniel Plücken <daniel@debakel.net>
* @see http://www.php.net/manual/en/function.imagecolortransparent.php#78379
* @param string $to_width
$dbl_aspect_ratio = $act_height / $act_width;
$to_height = $to_width * $dbl_aspect_ratio;
// Transparency only available for GIFs & PNGs
// (Try to preserve transparency info)
if ( $this->kind == "PNG" || $this->kind == "GIF" )
// If we have a specific transparent color
// Get the original image's transparent color's RGB values
// Allocate the same color in the new image resource
// Completely fill the background of the new image with allocated
// Set the background color for new image to transparent
// Always make a transparent background color for PNGs that don't have
if ( $this->kind == "PNG" )
// Turn off transparency blending (temporarily)
// Create a new transparent color for image
// Completely fill the background of the new image with allocated
// Restore transparency blending
$to_width, $to_height, $act_width, $act_height
$to_width, $to_height, $act_width, $act_height
* Scales the image to the given height and keeps the aspect ratio. Trys to
* preserve transparency info for GIFs & PNGs.
* @author Daniel Plücken <daniel@debakel.net>
* @see http://www.php.net/manual/en/function.imagecolortransparent.php#78379
* @param string $to_height
$dbl_aspect_ratio = $act_width / $act_height;
$to_width = $to_height * $dbl_aspect_ratio;
// Transparency only available for GIFs & PNGs
// (Try to preserve transparency info)
if ( $this->kind == "PNG" || $this->kind == "GIF" )
// If we have a specific transparent color
// Get the original image's transparent color's RGB values
// Allocate the same color in the new image resource
// Completely fill the background of the new image with allocated
// Set the background color for new image to transparent
// Always make a transparent background color for PNGs that don't have
if ( $this->kind == "PNG" )
// Turn off transparency blending (temporarily)
// Create a new transparent color for image
// Completely fill the background of the new image with allocated
// Restore transparency blending
$to_width, $to_height, $act_width, $act_height
$to_width, $to_height, $act_width, $act_height
* Returns the height of the image.
* @author Daniel Plücken <daniel@debakel.net>
* Returns the width of the image.
* @author Daniel Plücken <daniel@debakel.net>
* Returns the content of this image file object.
* @author Daniel Plücken <daniel@debakel.net>
|