Simple php image proportional scaling code. I used getimagesize to get the size of the original image, and then x0.5 is to set the image to 5. Arraygetimagesize (string $ filename [, array $ imageinfo]) The getimagesize () function is used to determine whether to use getimagesize to obtain the size of the original image and then use x0.5 to get the image/5.
Array getimagesize (string $ filename [, array & $ imageinfo])
The getimagesize () function will determine any gif, jpg, png, swf, swc, pstutorial d, tiff, bmp, iff, jp2, jpx, jb2, jpc, the size of the xbm or wbmp image file, the size of the returned image, the file type, and a height/width text string that can be used in a common html file.
If you cannot access the image specified by filename or the image is not valid, getimagesize () returns false and generates an e_warning error.
*/
// Define a file
Using filename='1.jpg ';
$ Percent = 0.5;
// Send the header file
Header ('content-type: image/jpeg ');
// Obtain the image size
List ($ width, $ height) = getimagesize ($ filename );
// Define the new size
$ New_width = $ width * $ percent;
$ New_height = $ height * $ percent;
$ Image_p = imagecreatetruecolor ($ new_width, $ new_height );
/*
: Int imagecreate (int x_size, int y_size );
Return value: integer
Description
This function is used to create an empty graph. The x_size and y_size parameters are the image sizes in pixels ).
*/
$ Image = imagecreatefromjpeg ($ filename );
/*
Resource imagecreatefromjpeg (string filename) imagecreatefromjpeg () returns an image identifier, representing the image obtained from the given file name. Imagecreatefromjpeg () returns an empty string upon failure and outputs an error message. Unfortunately, it is displayed as a broken link in the browser. The following example generates an error jpeg to reduce debugging:
*/
Imagecopyresampled ($ image_p, $ image, 0, 0, 0, $ new_width, $ new_height, $ width, $ height );
/*
): Imagecopyresamples (), the image edge obtained by its pixel interpolation algorithm is relatively smooth. good quality (but this function is slower than imagecopyresized ). the parameters of the two functions are the same. imagecopyresampled (dest, src, dx, dy, sx, sy, dw, dh, sw, sh );
*/
// Output image
Imagejpeg ($ image_p, null, 100 );
/*
Run the code to scale the original image by 50% and output the new image.
*/
Bytes. Array getimagesize (string $ filename [, array $ imageinfo]) The getimagesize () function will be determined by any...