Pages

Saturday, 30 April 2016

imagejpeg PHP GD Function

Creates and output an image to browser or saved into a file

Syntax:

bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )

Argument Detail:

image
An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().

filename
The path to save the file to. If not set or NULL, the raw image stream will be outputted directly.

To skip this argument in order to provide the quality parameter, use NULL.

quality
quality is optional, and ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file). The default is the default IJG quality value (about 75).

example : 


list($width, $height) = getimagesize($_FILES['file']['tmp_name']);
$thumb = imagecreatetruecolor(300, 200); //Add your custom image size
$source = imagecreatefromjpeg($_FILES['file']['tmp_name']);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, 300, 200, $width, $height);
$filename = "small/". $_FILES['f1']['name']; //small is a folder where resized image will be saved

imagejpeg($thumb,$filename,100);
$msg= "Resized";

No comments:

Post a Comment