Phpob_start () implements the variable program for storing images. After processing images with the phpGD library, you can only use imagejpeg () this is not required for output or writing to a file. for example, if you want to store images in a database, you need to write the images in the php GD Library. after processing the images, you can only use imagejpeg () this is often not required for output or writing to a file. for example, to store images in a database, you need to write the images into variables and save them. use ob_start () to enable cache ob_get_contents () get the cache to write the image to the variable
| The code is as follows: |
|
|
$ ImgPath = "Image address ";
// Obtain image information $ imgPath can be a remote address
List ($ srcWidth, $ srcHeight, $ type) = getimagesize ($ imgPath );
...
Switch ($ type ){
Case 1: $ imgCreate = 'imagecreatefromgif'; break;
Case 2: $ imgCreate = 'imagecreatefromjpeg '; break;
Case 3: $ imgCreate = 'imagecreatefrompng '; break;
Default: return false;
}
$ Orig = $ imgCreate ($ imgPath );
...
// Enable cache
Ob_start ();
// Generate an image
Switch ($ type)
{
Case 1: imagegif ($ orig); break;
Case 2: imagejpeg ($ orig); break; // best quality
Case 3: imagepng ($ orig); break; // no compression
Default: echo ''; break;
}
// Save the image to a variable
$ ImageCode = ob_get_contents ();
Ob_end_clean (); |
If you do not want to save the image as a variable, it will be a waste of resources. this is also a fun test.
After processing the image, the GD library can only output the image using imagejpeg () or write it into a file. this is often not required. for example, to store the image in the database, you need to write the image...