What are the potential pitfalls of using the GD library for image manipulation in PHP?

One potential pitfall of using the GD library for image manipulation in PHP is the lack of support for certain image formats, such as GIF. To solve this issue, you can use the Imagick extension instead, which provides better support for various image formats.

// Check if Imagick extension is available
if (extension_loaded('imagick')) {
    // Use Imagick for image manipulation
    $image = new Imagick('image.jpg');
    $image->resizeImage(200, 200, Imagick::FILTER_LANCZOS, 1);
    $image->writeImage('resized_image.jpg');
} else {
    // Use GD library as fallback
    $image = imagecreatefromjpeg('image.jpg');
    $resized_image = imagescale($image, 200, 200);
    imagejpeg($resized_image, 'resized_image.jpg');
    imagedestroy($image);
    imagedestroy($resized_image);
}