Location: PHPKode > scripts > clsImage > clsimage/class.image.documentation.html
<html>
<head>
<title>PHP CLASS clsImage documentation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="php,class,image,php4,php5,zend,gd,library,free,manipulation,photo,resize,crop,text,write">
<meta name="description" content="PHP class clsImage - A image manipulation class for PHP with Zend engine and GD library. With this class you can easily change sizes of images or write text on images right on the Internet.">
<meta name="copyright" content="&#169; 2004 ZUTZ Automatisering">
<meta name="distribution" content="Global">
<meta name="robots" content="index, follow">
<meta name="revisit-after" content="30 days">
<base target="_blank">
<style type="text/css">
<!--
.code {
	font-family: "Courier New", Courier, mono;
	font-size: 12px;
	font-weight: bold;	
	color: #333333;
	vertical-align: top;
	height: 30px;
	width: 500px;		
}
.explain {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #333333;
	vertical-align: top;		
}
.version {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 10px;
	color: #333333;
	vertical-align: top;		
}
.downloadcount {
	font-family: "Courier New", Courier, mono;
	font-size: 14px;	
	color: #990000;		
}
body {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;	
	color: #000000;
}
-->
</style>
</head>
<body>
<h2><font color="#000066">PHP CLASS clsImage</font></h2>
<table width="200" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="version"><font color="#FF6600">version</font></td>
    <td class="version">1.0</td>
  </tr>
  <tr>
    <td class="version"><font color="#FF3300">released</font></td>
    <td class="version">9 december 2004</td>
  </tr>
  <tr>
    <td class="version"><font color="#FF9900">author</font></td>
    <td class="version">ronald zötsch</td>
  </tr>
    <td class="version"><font color="#FF9966">feedback</font></td>	
    <td class="version"><a href="mailto:ronald.zotsch (at) zutz.nl?subject=Ronald Zötsch | ZUTZ Automatisering | feedback PHP class clsImage">ronald.zotsch (at) zutz.nl</a></td>
</table>
<hr>
<p>The custom <strong>PHP</strong> <strong>class</strong> clsImage can be used to <strong>manipulate
    images</strong>. With this
  class you can easily <strong>change the size</strong> (with or without resize
  ratio), <strong>write
  text on</strong> the image or <strong>crop</strong> an image to a certain size The class clsImage uses
  a few configuration parameters, is easy to setup and is very easy to use.</p>
<p>Images of the type <strong>JPEG</strong>, <strong>GIF</strong> or <strong>PNG</strong> (.jpg .gif .png) can be used with the
  class clsImage, you can <strong>convert</strong> types in memory and <strong>save</strong> the image <strong>to
  disk</strong>  with a
  new file
  extension
  and imagetype. With JPG images a default image <strong>quality</strong> or custom image quality
  can be set. With GIF and JPEG images an <strong>interlace</strong> option can be used, if interlace
  is set for a JPEG image the  image will become a <strong>progressive</strong> <strong>JPEG</strong>. Imagequality
  and interlace/progressive are applied when when saving the imageobject to file.</p>
<p><strong>Installation</strong> of this class is as simple as &quot;putting the files
  in your site-directory&quot;.
  Configuration parameters must be set in the <strong>config file</strong> which is included in
  the download-package. Your server (your own server or your ISP's server) must
  have the <strong>GD library</strong> available in the host environment, ask your system administrator
  or ISP to install and activate the GD library for your site. The classfile
  must be included in your PHP code and you can use the class in your code. Also
  read the rest of this <strong>documentation</strong> and examine the included <strong>example-file</strong> for
  extra information.</p>
<p>At
    this moment a<strong> free PHP5 </strong>and<strong> PHP4 version</strong> are
    available, these versions are <strong>tested</strong> on a Windows 2000 SP4
    server with <strong>IIS</strong> and<strong> PHP5</strong> with
    the <strong>Zend</strong> engine and <strong>GD library</strong> and on a
    UNIX / Linux server with <strong>apache</strong> and <strong>PHP4</strong> with the Zend engine and GD library. </p>	
<table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="150"><strong>GD library</strong></td>
    <td><a href="http://www.boutell.com/gd/">http://www.boutell.com/gd/</a></td>
  </tr>
  <tr>
    <td><strong>PHP4 &amp; PHP5</strong></td>
    <td><a href="http://www.php.net/">http://www.php.net/</a></td>
  </tr>
  <tr>
    <td><strong>Zend</strong></td>
    <td><a href="http://www.zend.com/zend/download-php.php">http://www.zend.com/zend/download-php.php</a></td>
  </tr>
</table>
<h3>Download the <font color="#FF3300">FREE</font> class <a href="http://www.zutz.nl/phpclasses/download/download.class.php?class=clsimage">clsImage</a></h3>
<h3>View a <font color="#FF3300">live demo</font> of the class <a href="class.image.example.php">clsImage</a>  (demo
  version PHP4/UNIX)</h3>
<b>the downloadfile <font color="#000066">class.image.zip</font> contains the following files</b>:<br>
<br>
<strong>PHP5 / </strong>UNIX /<strong> WINDOWS</strong>
<ul>
  <li><font color="#000066">class.image.php5.php</font></li>
  <li><font color="#000066">class.image.interface.php</font></li>
  <li><font color="#000066">class.image.config.win.php</font></li>
  <li><font color="#000066">class.image.config.unix.php</font></li>
  <li><font color="#000066">class.image.example.php5.php</font></li>
  <li><font color="#000066">class.image.debug.code.php</font></li>
</ul>
<strong>PHP4 / UNIX</strong> / WINDOWS
<ul>
  <li><font color="#000066">class.image.php4.php</font></li>
  <li><font color="#000066">class.image.config.win.php</font></li>
  <li><font color="#000066">class.image.config.unix.php</font></li>
  <li><font color="#000066">class.image.example.php4.php</font></li>
  <li><font color="#000066">unix-fonts.tar.gz</font></li>
</ul>
<strong>Documentation</strong>
<ul>
  <li><font color="#666666">class.image.documentation.html</font></li>
  <li><font color="#666666">class.image.release.txt</font></li>
</ul>
</p>
<table width="300" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><font color="#990000" size="2" face="Courier New, Courier, mono">THIS SOFTWARE IS PROVIDED "AS IS" AND
        WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION,
        THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.</font></td>
  </tr>
</table>
<hr>
<h2><font color="#000066">Documentation</font></h2>
<h3><font color="#666666">Some examples of PHP code  with the class clsImage</font></h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="code">$objPhoto = new clsImage;</td>
    <td class="explain">create a new imageobject based on the class clsImage</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">$objPhoto-&gt;loadfile(&quot;test.gif&quot;);</td>
    <td class="explain">load a imagefile from disk into the imageobject in memory</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">$objPhotoResize = clone($objPhoto);</td>
    <td class="explain">make a copy of the (original) imageobject in memory. (only for PHP5)</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="code">$objPhotoResize = $objPhoto;</td>
    <td class="explain">make a copy of the (original) imageobject in memory. (for PHP4)</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>		
  <tr>
    <td class="code">$objPhotoResize->resize(100,100);</td>
    <td class="explain">resize the copied imageobject to width: 100 and height: 100. the resize
        will be executed on the imageobject in memory. with this resize method
      the size-ratio is not kept so disformation of the image can occur</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">$objPhotoResize->writetext('resized',16,'255,0,0','trebuc',30,80,45);</td>
    <td class="explain">write the text &quot;resized&quot; on the imageobject in memory, text can be written
      on different positions and angles. also different fonts and colors can
      be used</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">$objPhotoResize->convert('jpg');</td>
    <td class="explain">convert the image to a JPEG image. The conversion is performed by setting an imagetype property and executing the corresponding image[ jpeg|gif|png ]() functions of the GD library when saving the memoryimage to file.</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">$objPhotoResize->jpegquality = 70;</td>
    <td class="explain">set the image quality of the JPEG imageo to 70.
      This value will be applied when saving the imageobject from memory to file</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">$objPhotoResize->interlace = true;</td>
    <td class="explain">set interlace on for the JPEG image, with JPEG images
      the interlace option will set the JPEG image to a progressive JPEG</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>		
  <tr>
    <td class="code">$objPhotoResize->savefile('test-resized.jpg');</td>
    <td class="explain">save the imageobject in memory to disk</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">$objPhotoResize->showhtml("a resized image");</td>
    <td class="explain">show the image as a html-tag, the imagefile is used for displaying the
      image (not the memory image)</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">print $objPhotoResize->filename;</td>
    <td class="explain">print the filename of the imageobject in memory.</td>
  </tr>
</table>
<h3><font color="#000066">clsImage</font><font color="#333333">::</font><font color="#FF6600">properties</font></h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="code">&nbsp;</td>
    <td class="explain" colspan="2"><em>applies only to PHP5</em></td>		
  </tr>
  <tr>
    <td class="code">clsImage->filename</td>
    <td width="150" class="explain"><strong>private</strong> <font color="#993333">read</font></td>		
    <td class="explain"><b>string</b>: the filename of the imageobject in memory</td>
  </tr>	
  <tr>
    <td class="code">clsImage->height</td>
    <td width="150" class="explain"><strong>private</strong> <font color="#993333">read</font></td>		
    <td class="explain"><b>integer</b>: the height of the imageobject in memory</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>		
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->width</td>
    <td class="explain"><strong>private</strong> <font color="#993333">read</font></td>		
    <td class="explain"><b>integer</b>: the width of the imageobject in memory</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>		
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->orientation</td>
    <td class="explain"><strong>private</strong> <font color="#993333">read</font></td>		
    <td class="explain"><b>string</b>: the orientation of the imageobject in memory<br><br>		<strong>OPTIONS</strong> [
      portrait | landscape | square ]<br></td>
  </tr>	
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>		
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->mimetype</td>
    <td class="explain"><strong>private</strong> <font color="#993333">read</font></td>		
    <td class="explain"><b>string</b>: the mimetype of the imageobject in memory<br><br>		<strong>OPTIONS</strong> [ image/jpeg
      | image/gif | image/png ]<br></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>		
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->type</td>
    <td class="explain"><strong>private</strong> <font color="#993333">read</font></td>		
    <td class="explain"><b>integer</b>: the imagetype of the imageobject in memory<br><br>		<strong>OPTIONS</strong> [ 1 = GIF | 2 = JPEG | 3 = PNG ]<br></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>		
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->interlace</td>
    <td class="explain"><strong>public</strong> <font color="#993333">read/change</font></td>		
    <td class="explain"><b>boolean</b>: interlace image on save<br><br>
		<strong>OPTIONS</strong> [ true
      | false ]<br></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>		
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->jpegquality</td>
    <td class="explain"><strong>public</strong> <font color="#993333">read/change</font></td>		
    <td class="explain"><b>integer</b>: the JPEG quality of the image, applied
      when saving the imageobject in memory to file<br><br>			<strong>RANGE</strong> [ 1..100 ]<br></td>
  </tr>
</table>
<h3><font color="#000066">clsImage</font><font color="#333333">::</font><font color="#FF6600">methods</font></h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="code">clsImage->loadfile(string: filename)</td>
    <td class="explain">load a imagefile into the imageobject in memory</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->savefile(string: filename)</td>
    <td class="explain">save the imageobject in memory to file</td>
  </tr>
  <tr>
    <td class="code">clsImage->preview()</td>
    <td class="explain">preview the imageobject in memory by sending a new header with the memoryimage to the client (script terminates)</td>
  </tr>	
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->showhtml(string: htmlalttext, string: htmlclassname)</td>
    <td class="explain">show the imagefile as a htmltag &lt;IMG&gt; with optional ALT-text and CSS class</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->resize(integer: newwidth, integer: newheight)</td>
    <td class="explain">resize the memoryimage to a given width and height, do not keep the size-ratio</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->convert(string: imagetype)</td>
    <td class="explain">convert the imageobject in memory to another type, conversion
      will be applied when saving to file. options are: [ jpg | gif | png ]</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->resizetowidth(integer: newwidth)</td>
    <td class="explain">resize the imageobject in memory to a given width, keep size-ratio</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->resizetoheight(integer: newheight)</td>
    <td class="explain">resize the imageobject in memory to a given height, keep size-ratio</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="code">clsImage->resizetopercentage(integer: resizepercentage) </td>
    <td class="explain">resize the imageobject in memory to a given percentage, keep size-ratio</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>			
  <tr>
    <td class="code">clsImage->crop(integer: newwidth, integer: newheight, integer:
      resizepercentage)</td>
    <td class="explain">crop the imageobject in memory to a given width and height,
      keep size-ratio. the image can be resized first to a given percentage to
      enlarge or shrink the image before cropping</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>	
  <tr>
    <td class="code">clsImage->writetext(string: text, integer: fontsize, string:
      textcolor ['R,G,B'], string: fontfilename, integer: x-pos, integer: y-pos,
    integer: angle)</td>
    <td class="explain">write text on the imageobject in memory</td>
  </tr>			
</table>
<h3><font color="#666666">Examples of images manipulated with the clsImage class</font></h3>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="300"><img src="examples/test.jpg"></td>
    <td>the original image</td>
	</tr>
	<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
	</tr>			
	<tr>
    <td><img src="examples/test-resized.png"></td>
    <td>resized to 100x100 pixels without size-ratio and text written on the
      image</td>
	</tr>
	<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
	</tr>			
	<tr>		
    <td><img src="examples/test-resized-width.gif"></td>
    <td>resized to width 150 pixels</td>
	</tr>	
	<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
	</tr>		
	<tr>		
    <td><img src="examples/test-cropped.jpg"></td>
    <td>cropped to 200x150 pixels with size-ratio</td>
	</tr>
	<tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
	</tr>			
	<tr>		
    <td><img src="examples/test-cropped2.jpg"></td>
    <td>cropped to 100x100 pixels with size-ratio</td>
  </tr>
</table>
<hr>
<b>The <font color="#006633">class clsImage</font> is provided by </b><font color="#FF6600"><strong>ZUTZ</strong></font><b> <em><font color="#000066">Automatisering</font></em> (<a href="http://www.zutz.nl">http://www.zutz.nl</a>)
and is available as <font color="#993300">FREE</font> <font color="#000099">Public Domain code</font></b>
</body>
</html>
Return current item: clsImage