What are the differences between using ImageMagick and GD library for generating thumbnails in PHP?

When generating thumbnails in PHP, ImageMagick and GD library are two popular options. ImageMagick generally provides better image quality and more advanced features, but it may require additional server configurations. On the other hand, GD library is simpler to use and is usually already installed on most servers.

// Using GD library for generating thumbnails
$source_image = 'original.jpg';
$thumbnail_image = 'thumbnail.jpg';

list($width, $height) = getimagesize($source_image);
$thumb_width = 100;
$thumb_height = 100;

$source = imagecreatefromjpeg($source_image);
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);

imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);

imagejpeg($thumb, $thumbnail_image);
imagedestroy($source);
imagedestroy($thumb);