0byt3m1n1
Path:
/
home
/
kassiope
/
www
/
administrer
/
class
/
[
Home
]
File: img_class.old.php
<?php /** *klasa do obsugi obrazeczka * * duuuugi opis ... * @package CMS * @author HaRy(at)rnet(dot)pl * @version 0.4 * @abstract * @copyright HaRy(at)rnet(dot)pl */ class img { /** * Uchwyt obrazka * * @access private * @var resource */ var $_resImg; /** * Dopuszczalne typy obrazka wraz z odpowiednimi rozszerzeniem * @var array */ var $arrTypes = array ( "jpeg" => "jpeg", "jpg" => "jpeg", "pjpeg" => "jpeg", "png" => "png", "gif" => "gif", ); /** * Typ obrazka, kt�y obrabiamy. * @access public * @var string */ var $strType = ''; /** * Docelowy format pliku. * @access public * @var string */ var $strDestType = ''; /** * ostatnia X pozycja tekstu * @access private * @var int */ var $_intXPosText = 0; /** * Konstruktor klasy <i>img</i> * @param string $strFilename * @param $strDestType - format pliku ko�owego. * @return bool * @uses img::czytaj czyta i zwraca tablice obrazka * @uses img::klucz zwraca mime z tablicy obrazka */ var $height =0; var $width=0; var $type=-10; function img( $strFilename ,$strDestType = "jpeg" ) { if ( is_array( $this->czytaj( $strFilename ) ) ) { if( array_key_exists( $strtype = strtolower ( array_pop( explode( "/", $this->klucz( $this->czytaj( $strFilename ), 'mime' ) ) ) ), $this->arrTypes ) ) { $this->strType = $strtype; $strFuncName = 'imagecreatefrom'.$this->strType; $this->_resImg = $strFuncName( $strFilename ); $this->strDestType = $strDestType; $size=getimagesize($strFilename); $this->width=$size[0]; $this->height=$size[1]; $this->type=$size[2]; // print_r($size); // echo $this->strType; return $this->_resImg; } else { return 0; } // end if } else { return -1; } // end if } // end construktor img /** * Czytanie pliku o podanej ciece * <b>Przykad wyniku:</b> * <code> * Array * ( * [0] => 200 * [1] => 150 * [2] => 2 * [3] => width="200" height="150" * [bits] => 8 * [channels] => 3 * [mime] => image/jpeg * ) * </code> * @access public * @param string $strFilename - scieka do pliku. * @return array. */ function czytaj( $strFilename ) { if ( !( $strFilename ) ) { return false; } // end if $arrdata = @getimagesize( $strFilename ); if ( !(is_array( $arrdata ) ) ) { return false; } else { return $arrdata; } // end if } // end function read /** * Zmiana Gammy obrazka ... * * ... czyli rozjanienie lub zciemnienie. * * @access public * @param int $intGamma - stopie�zmiany gammy obrazka (6 - normal) * @return bool */ function gamma( $intGamma ) { if ( !( imagesx( $this->_resImg ) ) ) { return false; } elseif ( !( imagegammacorrect( $this->_resImg, 1.6, (double)($intGamma/10+1) ) ) ) { return false; } else { return true; } // end if } // end function gamma /** * Uchwyt koloru. * * @access public * @param string $strColor - kod koloru (heksadecymalny) * @return int */ function check($max_width,$max_height) { if($this->width > $max_width) return -1; // Zdj�ie jest za szerokie if($this->height > $max_height) return -2; // Zdj�ie jest za wysokie return $this->type; } function color( $strColor = '000000@0' ) { $intRed = hexdec( substr( $strColor, 0, 2 ) ); $intGreen = hexdec( substr( $strColor, 2, 2 ) ); $intBlue = hexdec( substr( $strColor, 4, 2 ) ); $intAlpha = ( strpos($strColor,"@") == 6 ? intval( array_pop( explode( "@", $strColor ) ) ) : 0 ); return @imagecolorallocatealpha( $this->_resImg, $intRed, $intGreen, $intBlue, $intAlpha ); } // end function color /** * Prostokt * * @access public * @param int $intX1 - warto�X punktu 1 * @param int $intY1 - warto�Y punktu 1 * @param int $intX2 - warto�X punktu 2 * @param int $intY2 - warto�Y punktu 2 * @return bool */ function rectangle( $intX1, $intY1, $intX2, $intY2, $intColor ) { $arrPoints = array( "0" =>$intX1, "1" =>$intY1, "2" =>$intX2, "3" =>$intY1, "4" =>$intX2, "5" =>$intY2, "6" =>$intX1, "7" =>$intY2 ); return imagefilledpolygon( $this->_resImg, $arrPoints, 4, $intColor ); } // end function rectangle /** * Rysowanie linii na obrazeczku. * * @access public * @param int $intX1 - warto�X punktu 1 * @param int $intY1 - warto�Y punktu 1 * @param int $intX2 - warto�X punktu 2 * @param int $intY2 - warto�Y punktu 2 * @param int $strColor - uchwyt koloru otrzymany funkcja img::color() * @return bool */ function line( $intX1, $intY1, $intX2, $intY2, $intColor ) { if( !( imageline( $this->_resImg, $intX1, $intY1, $intX2, $intY2, $intColor ) ) ) { return false; } else { return true; } //end if } // end return line function border( $intBorder = 1, $intColor) { if ( @imagesx( $this->_resImg ) and intval( $intBorder ) > 0 ) { for ($i=0; $i <= intval($intBorder); $i++) { $this->line( 0 + $i, 0 + $i, imagesx($this->_resImg) - $i, 0 + $i, $intColor ); $this->line( 0 + $i, 0 + $i, 0 + $i, imagesy($this->_resImg) - $i, $intColor ); $this->line( imagesx($this->_resImg) - $i,0 + $i, imagesx($this->_resImg) - $i, imagesy($this->_resImg) - $i, $intColor ); $this->line( 0 + $i, imagesy($this->_resImg) - $i, imagesx($this->_resImg) - $i, imagesy($this->_resImg) - $i, $intColor ); } // end for } else { return false; } } // end function border /** * Obr� obrazka o $intAngle stopni przeciwnie do ruchu wskaz�ek zegara * * @access public * @param int $intAngle - warto�w stopniach obrotu. * @param int $intColor - kolor wypeniajcy ew. braki po obrocie. * @return bool */ function rotate( $intAngle = 90, $intColor = false ) { $this->_resImg = imagerotate( $this->_resImg, intval( $intAngle ), ( $intColor ? $intColor : $this->color( '000000' ) ) ); return true; } // end function rotate /** * Zmiana rozmiar� obrazka. * <b>Przykad:</b> * <code> * <?php * $objImg = new img( "http://example.com/example.gif" ); * $objimg->resampled( 400, 400, true ); //skalowanie obrazka do 400 px dluszej kraw�zi. * $obj->save( ); // wyswietlenie obrazka. * * @access public * @param int $intWidth - nowa szeroko�(0 w wypadku automaticu) * @param int $intHeight - nowa wysoko�(0 w wypadku automaticu) * @param bool $boolProportion - zmiejszanie promorcjonalne * @return bool */ function resampled( $intWidth, $intHeight, $boolProportion = true ,$type) { $intXorg = imagesx( $this->_resImg ); $intYorg = imagesy( $this->_resImg ); if ( ( !( intval( $intWidth ) ) && !( intval( $intHeight ) ) ) or ( !( imagesx( $this->_resImg ) /* jeeli false - co nie tak jest z obrazkiem :) */ ) ) ) { return false; } else { if ( $boolProportion ) { if(!isset($type)) if($intXorg < $intYorg) $type="height"; else $type="width"; if($type=="width") { $intXnew = $intWidth; $intYnew = round( $intYorg * intval( $intWidth ) / $intXorg ) ; } if($type=="height") { $intYnew = $intHeight; $intXnew = round( $intXorg * intval( $intHeight ) / $intYorg ); } // end if } elseif ( ( $intWidth ) and ( $intHeight ) ) { $intXnew = $intWidth; $intYnew = $intHeight; } else { return false; } // end if ( $boolProportion ) // echo '|'.$intXnew.'--'.$intYnew.'|<BR>'; $resTmp =@imagecreatetruecolor( $intXnew, $intYnew ); if( imagecopyresampled( $resTmp, $this->_resImg, 0, 0, 0, 0, $intXnew, $intYnew, $intXorg, $intYorg ) ) { $this->_resImg=$resTmp; return true; } // else { return false; } //end imagedestroy($resTmp); } //end if }// end function resampled /** * napis pixelartowym zwykym fontem * * @param int $intX - pozycja X tekstu * @param int $intY - pozycja Y tekstu * @param string $strText - napis * @param int $intColor - uchwyt koloru. * @param int $intSize - Font (<b>1</b>-<b>5</b>) + efekty dzialania funkcji <i>img::loadfont( );</i> * @param bool $boolNextLine - czy po napisani tekstu ma przejsc do next line ;) * @return bool */ function string( $intX, $intY, $strText, $intColor, $intFont = 3, $boolNextLine = true ) { $intX = intval( $intX ) + $this->_intXPosText; $intY = intval( $intY ); $strText = trim( $strText ); $this->_intXPosText = intval( ( $boolNextLine === false ) ? ( imagefontwidth( $intFont )*strlen( $strText )+$intX ) : 0 ); if ( !( strlen( $strText ) ) or ( $intX > @imagesx( $this->_resImg) ) or ( $intY > @imagesy( $this->_resImg ) ) or ( !( @imagesx( $this->_resImg ) ) ) ) { return false; } else { return @imagestring( $this->_resImg, $intFont, $intX, $intY, $strText, $intColor ); } //end if } // end function string /** * Zapisanie. lub wywietlnie obrazka. * * @access public * @param string $strFilename - opcjonalna nazwa pliku, w kt�ym ma zosta�zapisane r�o * @param integer $intQuality - jako�kompresji obrazka (w przypadku JPG) * @return bool */ function save( $strFilename = false, $intQuality =80 ) { if ( imagesx( $this->_resImg ) ) { if( !( $strFilename ) ) { header( "Content-type: image/".$this->strDestType ); header( "Content-Disposition: inline; filename=test".rand( 1, 100 ).".".$this->strDestType ); } else { $strDest = substr( $strFilename, strrpos($strFilename,".")+1, strlen($strFilename) ); } $strFc = ( isset( $strDest ) ? $strDest : $this->strDestType ); $strFc = ( $strFc === "jpg" ? "jpeg" : $strFc ); if ( $strFc == "jpeg" ) { $strCom = ' return image' . $strFc.'( $this->_resImg, "' . ( ( $strFilename ) ? $strFilename : false ) .'",'. intval( $intQuality ) . ' ); '; } else { $strCom = ' return image' . $strFc.'( $this->_resImg ' . ( ( $strFilename ) ? ',"'.$strFilename.'"' : false ) . ' ); '; } return eval( $strCom ); } else { return false; } // end if }//end function save /** * Zwalnia pami� zajmowan przez obrazek. * * @access public * @return bool */ function close( ) { if( imagesx( $this->_resImg ) ) { return imagedestroy( $this->_resImg ); } else { return false; } // end if } // end function close /** * Zwraca uchwyt obrazka. * * @access public * @return resource */ function returnImg() { return $this->_resImg; } // end function returnImg function gettype(){ return $this->strType; } /** *Funcja pomocnicza - zwraca z podanej tablicy ($arr) wybrany klucz ($key); * Przykad: * <code> * <?php * echo $this->klucz( getimagesize("www.example.com/example.gif"), "0" ); // zwr�i szeroko�obrazka. * ?> * </code> * @access public * @param array $arr - tablica z kt�ej potrzebujemy klucz * @param string $key - wybrany klucz * @return mixed */ function klucz( $arr, $key = '0' ) { if ( !( is_array( $arr ) ) ) { return false; } else { if ( !( isset( $arr[$key] ) ) ) { return false; } else { return $arr[$key]; } // end if } // end if } // end function klucz } ?>