<? Php Tutorial
Class My_Lib_simpleimage {
Var $ image;
Var $ image_type;
Function load ($ filename ){
// $ Temporary file name of the filename File $ _ FILES ['name'] ['tmp _ name']
$ Image_info = getimagesize ($ filename );
$ This-> image_type = $ image_info [2];
If ($ this-> image_type = IMAGETYPE_JPEG ){
$ This-> image = imagecreatefromjpeg ($ filename );
} Elseif ($ this-> image_type = IMAGETYPE_GIF ){
$ This-> image = imagecreatefromgif ($ filename );
} Elseif ($ this-> image_type = IMAGETYPE_PNG ){
$ This-> image = imagecreatefrompng ($ filename );
}
}
Function save ($ filename, $ image_type = IMAGETYPE_JPEG, $ compression = 75, $ permissions = null ){
If ($ image_type = IMAGETYPE_JPEG ){
Imagejpeg ($ this-> image, $ filename, $ compression );
} Elseif ($ image_type = IMAGETYPE_GIF ){
Imagegif ($ this-> image, $ filename );
} Elseif ($ image_type = IMAGETYPE_PNG ){
Imagepng ($ this-> image, $ filename );
}
If ($ permissions! = Null ){
Chmod ($ filename, $ permissions );
}
}
Function output ($ image_type = IMAGETYPE_JPEG ){
If ($ image_type = IMAGETYPE_JPEG ){
Imagejpeg ($ this-> image );
} Elseif ($ image_type = IMAGETYPE_GIF ){
Imagegif ($ this-> image );
} Elseif ($ image_type = IMAGETYPE_PNG ){
Imagepng ($ this-> image );
}
}
Function getWidth (){
Return imagesx ($ this-> image );
}
Function getHeight (){
Return imagesy ($ this-> image );
}
# Setting the height of a thumbnail
Function resizeToHeight ($ height ){
$ Ratio = $ height/$ this-> getHeight ();
$ Width = $ this-> getWidth () * $ ratio;
$ This-> resize ($ width, $ height );
}
# Setting the width of a thumbnail
Function resizeToWidth ($ width ){
$ Ratio = $ width/$ this-> getWidth ();
$ Height = $ this-> getheight () * $ ratio;
$ This-> resize ($ width, $ height );
}
Function scale ($ scale ){
$ Width = $ this-> getWidth () * $ scale/100;
$ Height = $ this-> getheight () * $ scale/100;
$ This-> resize ($ width, $ height );
}
Function resize ($ width, $ height ){
$ New_image = imagecreatetruecolor ($ width, $ height );
Imagecopyresampled ($ new_image, $ this-> image, 0, 0, 0, 0, $ width, $ height, $ this-> getWidth (), $ this-> getHeight ());
$ This-> image = $ new_image;
}
}
?>