Refining the PHP gd library

I look through this code and went through the docs, but still don't understand how this should work. The code works fine, as it sits, but I'm wondering if I should output the title as png instead of jpeg.

What exactly is going on in this code? Is the png image converted to jpeg?

What I ultimately want to do is watermark all the gif, jpg, bmp and png images in the same directory. I output all the headers, regardless of the type of image, like jpg. It's right? Hope I make sense here, I'm a little tired.

$im2 = imagecreatefrompng($image)
imagecopy() and more code here
header("Content-Type: image/jpeg");
imagejpeg($im2,'',50);
+3
source share
4 answers

Which makes your code more or less as follows:

// Load the PNG file from disk into memory
$im2 = imagecreatefrompng($image) 

$im2 resource, . png jpeg; . "" , ; . .

// Some code which works with the image in memory, adding your watermark?
imagecopy() and more code here

// Tell the browser that we're output a JPG
header("Content-Type: image/jpeg");

jpg (.. http://host.com/image.jpg), . JPG PHP, . PHP , HTML , - stdout, echo, / <?php ?>.

// compress as a jpeg, and send to browser
imagejpeg($im2,'',50);

imagejpeg , jpg ( ) stdout ( ). null, ''. , 50, jpeg . 100 , 0 - .

+3

imagejpeg JPEG . , , . imagepng, imagegif ..

+1

GD PNG , , , (JPEG) .

imagecreatefrompng, , GD , , , PNG . , , . , , . imagejpeg.

+1

imagecreatefrompng PNG . - , GD.

imagejpeg jpeg. , jpeg .

+1

Source: https://habr.com/ru/post/1731026/


All Articles