A text about the W3_Image
This method define the image´s path.
You just need to use this method, if you don´t inform an image´s path when declare the class; and want to avoid inform the image´s path when use the others methods.
The set_image method will overwrite the image´s path information, if you have informed the image´s path in the constructor.
Note: An empty string in the set_image method´s parameter will be ignored.
<?php
$imageTmp = $_FILES["image"]["tmp_name"];
$objImage = new W3_Image('http://www.google.com/intl/en_ALL/images/logo.gif');
$objImage->set_image($imageTmp);
?>
In the example above, the image´s path reference will be informed in the set_image method.
This method returns the image´s mime type.
This method works with all image´s mime type that the getimagesize PHP function works. Know the list: GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, ou WBMP.
Note: If you don´t inform an image´s path, the image´s path informed with the set_image method or in the constructor will be used.
Example
<?php
$objImage = new W3_Image('photos/photo_1.jpg');
echo $objImage->get_mime_type();
?>
In the example above, the image´s mime type will be returned. In this case: image/jpeg.
This method returns the image´s extension.
This method works with all image´s extension that the getimagesize PHP function works. Know the list: GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, ou WBMP.
Note: If you don´t inform an image´s path, the image´s path informed with the set_image method or in the constructor will be used.
Example
<?php
$objImage = new W3_Image();
echo $objImage->get_extension('photos/photo_2.jpg');
?>
In the example above, the image´s extension will be returned. In this case: jpg.
This method returns an Array with the width and height of the image. This Array is flexible and can be accessed in a numeric or associative way.
Example
<?php
$objImage = new W3_Image();
$arrSizes = $objImage->get_sizes('photos/photo_3.jpg');
print_r($arrSizes); // Array ( [0] => 1263 [1] => 1650 [width] => 1263 [height] => 1650 )
?>
This method returns an integer with the image´s width.
Example
<?php
$objImage = new W3_Image();
echo $objImage->get_sizex('photo.jpg'); // Ex.: 800
?>
This method returns an integer with the image´s height.
Example
<?php
$objImage = new W3_Image();
echo $objImage->get_sizey('photo.jpg'); // Ex.: 600
?>
This method returns a string with the width and height information about the image and can be used in an IMG tag.
Example
<?php
$objImage = new W3_Image();
echo $objImage->get_attr('photo.jpg'); // width="800" height="600"
?>
This method show the image in the browser definig the corret mime´s type for it and stop the script execution.
Example
<?php
$objImage = new W3_Image();
$objImage->show('photo.jpg');
?>
This method force the browser do the download of the image.
Example
<?php
$objImage = new W3_Image();
$objImage->download('photo.jpg');
?>
Note: if the image was uploaded, a name will be generated for it. With that sintaxe: W3_Image.HASH_WITH_12_CHARACTERS.image´s extension
This method save the image in the current directory.
If the second parameter was informed, the image will be saved in the especified directory and with the especified name. It simulate a Save As method.
Note: if the image was uploaded, a name will be generated for it. With that sintaxe: W3_Image.HASH_WITH_12_CHARACTERS.image´s extension
Example
<?php
$objImage = new W3_Image():
$objImage->save('photo_15.jpg'); // Save the photo in the current directory with the original name
$objImage->save('photo_15.jpg','archives/photo_me.jpg'); // Save the photo in the archives directory with the name photo_me.jpg
?>
This method is used to rename an image or move it´s location.
Note: this method doesn´t function with remote image.
This method is used to delete an image.
Example
<?php
$objImage = new W3_Image():
$objImage->delete('photo_24.jpg');
?>
This method creates an image starting from another image (file or URL).
The second and third parameter specify the max width and height the image can have. The fourth parameter informs a name to the image and can be informed a location too. The fifth parameter informed the quality of the image, this number is from 0 to 100; 75 is the default number.
Example
<?php $imageTmp = $_FILES["image"]["tmp_name"]; $objImage = new W3_Image(); $objImage->create($imageTmp,400,300,'uploads_photos/photo_city.jpg'); ?>
In the example above, an image will be created in the uploads_photos directory with the name photo_city.jpg, 400 pixels of max width, 300 pixels of max height and 75 of quality.
This method rotate the image with the degree informed.
Note: to avoid overwrite the original image, you can use the set_image_name method, so a new rotated image will be created and you can preserve the original image.
Example
<?php
$objImage = new W3_Image();
$objImage->rotate('photo.jpg',180);
// Using the set_image_name method
$objImage = new W3_Image():
$objImage->set_image_name('photo_rotated.jpg');
$objImage->rotate('photo.jpg',90);
// Using the set_image_name method in a chaining way
$objImage->set_image_name('photo_rotated.jpg')->rotate('photo.jpg',90);
?>
This method apply a filter in the image.
The filters availabe are:
Note: to avoid overwrite the original image, you can use the set_image_name method, so a new rotated image will be created and you can preserve the original image.
Example
<?php
$objImage = new W3_Image();
// Sepia example
$objImage->set_image_name('photo_sepia.jpg')->filter('photo.jpg','sepia');
// Brightness example
$objImage->set_image_name('photo_brightness.jpg')->filter('photo.jpg','brightness',35);
// Colorize example
$objImage->set_image_name('photo_colorize.jpg')->filter('photo.jpg','colorize',5,10,207);
?>