Alter the Width of an Image and Add Text
Current Image (courtesy of Veronica Hutchins)
Select Width Change (-5 = Widest, 0 = no change, 5 = Narrowest)
SLAVE CODE FOLLOWS
<?php // resize image
$user_string = $_GET['sk'];
$user_array = explode(",", $user_string);
$narrow = $user_array[0];
$word = $user_array[1];
// get the images from files
$image = imagecreatefromjpeg("../images/jason-leung-Xaanw0s0pMk-unsplash_sm.jpg");
// get sizes of original
$width_orig = imagesx($image);
$height = imagesy($image);
// font
$font = "fonts/arial.ttf";
// font foreground color
$color = imagecolorallocate($image, 170, 255, 0);
// combines the image with text using the following specs
imagettftext($image, 24, 18, 20, $height - 12, $color, $font, $word);
// adjust the width for the new image
$width = $width_orig - ($width_orig * $narrow * .05);
// create a new image
$new_image = imagecreatetruecolor($width, $height);
// resample old to new image
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height);
// set the header for the new image
header("Content-type: image/jpeg");
// display the image
imagejpeg($new_image);
// destroy the image (i.e., release memory)
imagedestroy($new_image);
?>