Snippets - GD

Snippets index page

Change a png to a jpg - Anthony 14/6/2008

Any transparency is lost in this case as jpg does not support transparency. You can change from different formats by changing the imagecreatefrompng and the imagejpeg functions.

  1. <?php
  2. // Create a new image in the memory from the file 
  3. $png_image imagecreatefrompng"input.png" );
  4. // Save the image as output.jpg
  5. imagejpeg$png_image"output.jpg" );
  6. // Clear the memory of the tempory image 
  7. imagedestroy$png_image );
  8. ?>

For more examples and information check out the main Imagemagick section.

Change a png to a jpg View

Create some text as an image View

Crop an image View

Display image without saving View

Grayscale image View

Resize an image View

Rotate an image View

Watermark an image View