PHP gd library clarification -
I'm looking at this code and went through docs, but still do not understand how Should work. This code is just fine as well, but I am thinking that I should output the header as a PNG rather than JPEG.
What is actually going on in this code? Is the PGG image converted into JPEG?
What I have to do at the end is to mark all GIF, JPG, BMP and PGG images in the same directory. I am outputting all the headers regardless of the image type as JPG. is this correct? I hope that I'm making sense here, I'm tired.
$ im2 = imagecreatefrompng ($ image) imagecopy () and more code header ("content-type: image / jpeg"); Imagejpeg ($ IM2, ', 50);
Makes your code more or less as:
< Pre> // Load PNG file into memory $ im2 = imagecreatefrompng ($ image)
$ im2
Now a resource
, referring to an image once in memory, it is not a png or jpeg; This is a raw, uncompressed data, the "format" of an image specifies how raw data is packaged and formatted; At this point, it is is not such a formatting. It is just data in memory.
// Some codes that work with the image in memory, adding your watermark? Imagecopy () And here's more code // tell the browser that we are outputting the JPG header ("content-type: image / JPEG");
If you request a JPG (ie), the server takes care to write this header for you. If you are making a JPG on the fly, then you have to output the header manually. Otherwise, PHP assumes that you are writing HTML and you can output to the appropriate headers like echo
or just
// jpeg, and send it to Browser Images ($ im2, '', 50);
imagejpeg
takes the raw image, compresses it as a JPG, and writes it in a file (if you give it a filename) Or stdout (which sends it to the browser) to technically output to the browser, the second argument should be null
, no ''
the last parameter, 50, JPG Specifies the quality as a percentage, 100 high quality, 0 low quality.
Comments
Post a Comment