// Load the image $image = imagecreatefromjpeg('original-image.jpg'); // Get the original image dimensions $width = imagesx($image); $height = imagesy($image); // Calculate the new dimensions for the thumbnail $new_width = 100; $new_height = floor($height * ($new_width / $width)); // Create a new image with the new dimensions $thumbnail = imagecreatetruecolor($new_width, $new_height); // Copy and resize the original image to the thumbnail imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Save the thumbnail image imagejpeg($thumbnail, 'thumbnail-image.jpg', 80);
// Load the image $image = imagecreatefrompng('original-image.png'); // Create a color for the text $text_color = imagecolorallocate($image, 255, 255, 255); // Add the text to the image imagestring($image, 5, 10, 10, 'Example Text', $text_color); // Save the modified image imagepng($image, 'modified-image.png');Both examples provided above are using the PHP GD image library.