00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00027 function scaleImage( $original, $destination, $width, $height )
00028 {
00029 if( checkImageMimetype( $original ) != false )
00030 {
00031 list( $x, $y ) = getimagesize( $original );
00032
00033
00034
00035 $x_ratio = $width / $x;
00036 $y_ratio = $height / $y;
00037 if( $x <= $width && $y <= $height )
00038 {
00039 $x2 = $x;
00040 $y2 = $y;
00041 }
00042 else if( ($x_ratio * $y) < $height )
00043 {
00044 $x2 = $width;
00045 $y2 = ceil( $x_ratio * $y);
00046 }
00047 else
00048 {
00049 $x2 = ceil( $y_ratio * $x );
00050 $y2 = $height;
00051 }
00052
00053 if( checkImageMimetype( $original ) == "jpg" )
00054 {
00055 $src = imagecreatefromjpeg( $original );
00056 $out = imagecreatetruecolor( $x2, $y2 );
00057
00058 imagecopyresampled( $out, $src, 0, 0, 0, 0, $x2, $y2, $x, $y );
00059 imagejpeg( $out, $destination );
00060 }
00061 else if( checkImageMimetype( $original ) == "png" )
00062 {
00063 $src = imagecreatefrompng( $original );
00064 $out = imagecreatetruecolor( $x2, $y2 );
00065
00066 {
00067 imagesavealpha( $out, true );
00068 imagealphablending( $out, false );
00069 $transparent = imagecolorallocatealpha( $out, 255, 255, 255, 0 );
00070 imagefilledrectangle( $out, 0, 0, $x2, $y2, $transparent );
00071 }
00072
00073 imagecopyresampled( $out, $src, 0, 0, 0, 0, $x2, $y2, $x, $y );
00074 imagepng( $out, $destination );
00075 }
00076 else if( checkImageMimetype( $original ) == "gif" )
00077 {
00078 $src = imagecreatefromgif( $original );
00079 $out = imagecreatetruecolor( $x2, $y2 );
00080 imagecopyresampled( $out, $src, 0, 0, 0, 0, $x2, $y2, $x, $y );
00081 imagegif( $out, $destination );
00082 }
00083 imagedestroy( $out );
00084 imagedestroy( $src );
00085
00086 $returnval = true;
00087 }
00088 else
00089 {
00090 if( checkImageMimetype( $original ) == false )
00091 $returnval = i18n( "Image type not supported or not an image file!" );
00092 else
00093 $returnval = i18n( "Unknown error" );
00094 }
00095
00096 return $returnval;
00097 }
00098
00112 function cropImage( $original, $destination, $topCornerX, $topCornerY, $width, $height )
00113 {
00114 $img = imagecreatetruecolor( $width, $height );
00115 $ext = checkImageMimetype( $original );
00116
00117 if( $ext == "jpg" )
00118 $org_img = imagecreatefromjpeg( $original );
00119 else if( $ext == "png" )
00120 $org_img = imagecreatefrompng( $original );
00121 else if( $ext == "gif" )
00122 $org_img = imagecreatefromgif( $original );
00123 else
00124 return i18n("The image type is not supported. Only jpeg, png and gif images are supported.");
00125
00126 $ims = getimagesize( $original );
00127
00128 if( $ext == "png" )
00129 {
00130 imagesavealpha( $img, true );
00131 imagealphablending( $img, false );
00132 $transparent = imagecolorallocatealpha( $img, 255, 255, 255, 0 );
00133 imagefilledrectangle( $img, 0, 0, $width, $height, $transparent );
00134 }
00135
00136 imagecopy( $img, $org_img, 0, 0, $topCornerX, $topCornerY, $ims[0], $ims[1]);
00137
00138 if( $ext == "jpg" )
00139 imagejpeg( $img, $destination, 90 );
00140 else if( $ext == "png" )
00141 imagepng($img, $destination );
00142 else if( $ext == "gif" )
00143 imagegif( $img, $destination );
00144
00145 imagedestroy($img);
00146
00147 return true;
00148 }
00149 ?>