Skip to content
PHP Logo

What role does the gdlib play in handling functions like imagecreatefromjpg in PHP?

The gdlib is a PHP extension that provides functions for image manipulation, such as imagecreatefromjpg, which is used to create an image resource from a JPEG file. To use functions like imagecreatefromjpg, the gdlib extension must be installed and enabled on the server. If the gdlib is not installed or enabled, functions like imagecreatefromjpg will not work.

php
// Check if the gd extension is enabled
if (!extension_loaded('gd')) {
    die('The GD extension is not enabled. Please enable it to use image functions.');
}

// Use imagecreatefromjpeg to create an image resource from a JPEG file
$image = imagecreatefromjpeg('image.jpg');

// Display the image
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);