header('Content-Type: image/jpeg'); $image = imagecreatefromjpeg('image.jpg'); imagejpeg($image); imagedestroy($image);
$image = imagecreatefrompng('image.png'); imagepng($image, 'output.png'); imagedestroy($image);
header('Content-Type: image/jpeg'); $src_image = imagecreatefromjpeg('image.jpg'); $dst_image = imagecreatetruecolor(100, 100); imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, 100, 100, imagesx($src_image), imagesy($src_image)); imagejpeg($dst_image); imagedestroy($src_image); imagedestroy($dst_image);In this example, we use the `imagecreatetruecolor` function to create a new true color image resource with a width and height of 100 pixels. We then use `imagecopyresampled` to copy and resample the source JPEG image to the new thumbnail image, and then render it to the browser output using `imagejpeg`. Finally, we destroy both the source and thumbnail image resources using `imagedestroy`. Package Library: GD Library Overall, the most common library used for image rendering in PHP is the GD Library. This library provides many functions for creating and manipulating images. Other popular image libraries in PHP include ImageMagick and Imagick.