// Load image $image = imagecreatefromjpeg('myimage.jpg'); // Get the current dimensions of the image $width = imagesx($image); $height = imagesy($image); // Define new dimensions for the image $new_width = 500; $new_height = 500; // Create a new blank image with the new dimensions $new_image = imagecreatetruecolor($new_width, $new_height); // Copy and resize the original image onto the new image imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Output the new image to a file or the browser header('Content-Type: image/jpeg'); imagejpeg($new_image, null, 100);
// Load image $image = imagecreatefromjpeg('myimage.jpg'); // Define font size and color $font_size = 24; $color = imagecolorallocate($image, 255, 255, 255); // Define text to be added to the image $text = 'Hello, World!'; // Define position of the text on the image $x = 100; $y = 100; // Add text to the image imagettftext($image, $font_size, 0, $x, $y, $color, 'arial.ttf', $text); // Output the new image to a file or the browser header('Content-Type: image/jpeg'); imagejpeg($image, null, 100);In both examples, we are using GD library to manipulate images in PHP.