Jump to content

when/why would a user need to imagecreatefrompng


dsdsdsdsd

Recommended Posts

hello;

 

I have only recently discovered that php has image-manipulation capabilities, which ofcourse is a different approach than using photoshop;

 

 

can anyone shed light on  when/why would a user need to imagecreatefrompng; seems to me if that a developer already has a png sitting on a server, there would not be a reason to create an image from it;

 

any thoughts?

 

 

thanks

dsdsdsds

Link to comment
Share on other sites

The image create functions are used when you wish to manipulate an image. If you wish to display a file with a watermark or other manipulation, and the original image is a PNG file, you would use said function. You would follow the same practice with a JPG, but use the createimagefromjpeg function call instead.

 

**EDIT**

Basically, think of it this way: the functions allow you to modify and display the image with modifications (or store it to disk) without ever actually modifying the original image.

Link to comment
Share on other sites

.png files are rather large, so if a user wanted a .jpg version, or a smaller version, you could convert it to reduce file size.

 

This is usually only the case of improperly optimized images, though. A standard PNG file vs JPG can be optimized to be smaller and look better than a JPG of the same size. The biggest issue is that IE6 doesn't appropriately support PNG transparencies :(

Link to comment
Share on other sites

all right; that makes sense;

 

I see also that I am going to necessarily have to deal with header( ... ) - something I have always avoided;

 

is there a library of all header values ( other than the php-referenced RFC 2616 (RFC2616) );

 

// PHP
// it seems that I must use something along the lines of     
header("Content-Type: image/png");
$img = ... 
imagepng( $img ) ;

// ...

// but that seems to effect the  ability to output html from the same php:
echo"<img id='non_dynamic_image' src='...' />" ;

 

 

 

thanks

dsdsdsdsd

Link to comment
Share on other sites

Another common use for the image libraries is to confirm that a file is in-fact an image.

 

For example, if you provide an upload script and I rename a php script to have a .jpg extension, depending on how you perform your validation your site may accept my file, even though it is not an image.  To validate that the file is actually an image, you might try and open it with the various image manipulation functions; if the functions fail then the file is not a valid image.

 

That said, I use finfo (or fileinfo) for the same functionality.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.