File indexing completed on 2024-12-22 05:33:23

0001 <?php
0002 
0003 /*
0004  *   TRT GFX 4.0 DyoMynchya
0005  * 
0006  *   support: happy.snizzo@gmail.com
0007  *   website: http://trt-gfx.googlecode.com
0008  *   credits: Claudio Desideri
0009  *   
0010  *   This software is released under the MIT License.
0011  *   http://opensource.org/licenses/mit-license.php
0012  */ 
0013 
0014 class EImage {
0015   
0016   /*
0017    * To be defined.
0018    */
0019   public function __construct()
0020   {
0021     //
0022   }
0023   
0024   /*
0025    * Makes a thumbnail mantaining the aspect ratio.
0026    * That's what $maxwidth and $maxheight are for.
0027    * WARNING: works only with JPG or PNG
0028    * 
0029    * @require php-gd
0030    */
0031   public function make_thumbnail($from,$to,$maxwidth,$maxheight)
0032   {
0033     $ext = EFileSystem::get_file_extension($from);
0034     if(!list($width, $height, $type, $attr) = getimagesize($from)){ ELog::error("$from |"); }
0035     if($width>$height){
0036       $x = $width/$maxwidth;
0037       $fwidth = floor($width / $x);
0038       $fheight= floor($height / $x);
0039     }
0040     if($width<$height){
0041       $x = $height/$maxheight;
0042       $fheight = floor($height / $x);
0043       $fwidth= floor($width / $x);
0044     }
0045     if($width==$height){
0046       if($maxwidth>$maxheight){ $max = $maxheight; } else { $max = $maxwidth; }
0047       $x = $height/$max;
0048       $fheight = floor($height / $x);
0049       $fwidth = floor($width / $x);
0050     }
0051     $thumb = imagecreatetruecolor($fwidth, $fheight);
0052     if($ext=="jpg" or $ext=="jpeg"){$source = imagecreatefromjpeg($from);}
0053     if($ext=="png"){$source = imagecreatefrompng($from);}
0054     imagecopyresized($thumb, $source, 0, 0, 0, 0, $fwidth, $fheight, $width, $height);
0055     if($ext=="jpg" or $ext=="jpeg"){imagejpeg($thumb, $to, 100);}
0056     if($ext=="png"){imagepng($thumb, $to, 1);}
0057     if($ext!="jpg" or $ext!="jpeg" or $ext!="png"){
0058       return false;
0059     } else {
0060       return true;
0061     }
0062   }
0063 }
0064 
0065 ?>