Php – Image Processing & Creation in PHP – How To Create 300DPI Images

image processingPHP

When creating images using the GD library in PHP ie) imagecreatetruecolor() what is the DPI of the resulting image? I haven't been able to find anyone specifying where the dpi can be set or what it defaults to.

I require a 300DPI tiff or jpeg to be created and then saved to the file system from the program.

If this isn't possible using the GD library, is there another that would work for this situation?

Thanks for your help

Edit: Yes this is creating an image – I would like to have a 300dpi file saved from the script not have to open up each file in photoshop to specify the dpi.

Best Answer

I don't think there's a way of setting DPI with GD. The DPI of an image is specified in the leading bytes of the image data - I believe for JPEG images that's bytes 15-18. Bytes 15-16 are horizontal DPI, 17-18 vertical. The values are stored as octals.

I'm a bit ropey with byte-level editing, but you could resize the image in GD to the target pixel size and then edit the file to adjust the DPI.