Small PHP class to create image thumbnails using the PHP GD Library
-
Copy the php file from the src folder into a folder on your server. It needs to be readable by your web server.
-
Include the file in your php with include or require methods.
loadImage(string $name)
Load the path to the original image
$name A string representing the path of the image.
save(string $name [, int $quality = 100] [, int $type = false])
Save the resulting image on disk
$name A string representing the path of the resulting image.
$quality An optional int between 0 and 100 that set the quality of the resulting image.
$type An optional int that set the format of the resulting image.
Posible values:
- IMAGETYPE_JPEG
- IMAGETYPE_PNG
- IMAGETYPE_GIF
show([int $type = false] [,boolean $base64 = false])
Show the resulting image directly on the page
$type An optional int that set the format of the resulting image.
Posible values:
- IMAGETYPE_JPEG
- IMAGETYPE_PNG
- IMAGETYPE_GIF
$base64 An optional boolean that specifies whether the flow of the image need to be printed directly on the page or if you want to return a base64 representation thereof for use as "src" parameter of an "img" element.
resize(int $value, string $reference)
Resize the image keeping its proportions
$value An int that set the width or the height of the resizing.
$reference A string that set if the image will be resized by its width or its height.
Posible values:
- width
- height
crop(int $width, int $height [, string $position = 'center'])
Create a crop of the image
$width An int that set the width of the cropping.
$height An int that set the height of the cropping.
$position An optional string that specify the position of the crop.
Posible values:
- center (default value)
- top
- right
- bottom
- left