<?php
//Allows unlimited execution time
set_time_limit(0);
//scan folder for jpg files and put them in an array
$images = glob('old/*.jpg');
//Sets font size and font file variables
$fontsize = 20;
$font = './3.ttf'; //place font in same folder as this script
//loop through array
foreach($images as $image) {
//basename create bare filename without folder/extension
$orig_text = basename($image, '.jpg');
//read current image into php resource $im that can be processed
$im = imagecreatefromjpeg($image);
//get width/height of image
$width = imagesx($im);
$height = imagesy($im);
//calculate width/height of new image adding on extra for borders
$new_width = $width + 60;
$new_height = $height + 95;
//create new image using the dimensions we've just worked out
$new_im = imagecreatetruecolor($new_width,$new_height);
//before you can use a colour, you have to define it first. uses RGB so 255, 255, 255 is white
$bg = imagecolorallocate($im, 255, 255, 255);
//fill our new image with this new colour
imagefill($new_im, 0 ,0, $bg);
//position the existing image into the new image
imagecopyresampled($new_im, $im, 30, 30, 0, 0, $width, $height, $width, $height);
//php function to caluclate width of text
$text_width = imagettfbbox($fontsize, 0, $font, $orig_text);
//definte our text colour -black in this case
$tc = imagecolorallocate($im, 0, 0, 0);
//If the width of the text is greater than the width of the image, then
if($text_width[2] > $new_width)
{
//explode text at first hyphen
$lines = split('-', $origtext);
//Filename with new line added
$final_text = implode("\n", $lines);
} else {
//else, Use the original text
$final_text = $orig_text;
}
//write the text using
imagettftext($new_im, $fontsize, 0, ($new_width - $text_width[2]) / 2, $new_height -20, $tc, $font, $filename);
//writes the completed image to the new folder
imagejpeg($new_im, 'new/' . $orig_text . '.jpg');
//free up resources
imagedestroy($im);
imagedestroy($new_im);
}
?>
<?php
//Allows unlimited execution time
set_time_limit(0);
//scan folder for jpg files and put them in an array
$images = glob('old/*.jpg');
//Sets font size and font file variables
$fontsize = 20;
$font = './3.ttf'; //place font in same folder as this script
//loop through array
foreach($images as $image) {
//basename create bare filename without folder/extension
$orig_text = basename($image, '.jpg');
//read current image into php resource $im that can be processed
$im = imagecreatefromjpeg($image);
//get width/height of image
$width = imagesx($im);
$height = imagesy($im);
//calculate width/height of new image adding on extra for borders
$new_width = $width + 60;
$new_height = $height + 95;
//create new image using the dimensions we've just worked out
$new_im = imagecreatetruecolor($new_width,$new_height);
//before you can use a colour, you have to define it first. uses RGB so 255, 255, 255 is white
$bg = imagecolorallocate($im, 255, 255, 255);
//fill our new image with this new colour
imagefill($new_im, 0 ,0, $bg);
//position the existing image into the new image
imagecopyresampled($new_im, $im, 30, 30, 0, 0, $width, $height, $width, $height);
//php function to caluclate width of text
$text_width = imagettfbbox($fontsize, 0, $font, $orig_text);
//definte our text colour -black in this case
$tc = imagecolorallocate($im, 0, 0, 0);
//If the width of the text is greater than the width of the image, then
if($text_width[2] > $new_width)
{
//split text at first hyphen
$lines = split('-', $origtext);
//Filename with new line added
$final_text = implode("\n", $lines);
} else {
//else, Use the original text
$final_text = $orig_text;
}
//write the text using
imagettftext($new_im, $fontsize, 0, ($new_width - $text_width[2]) / 2, $new_height -20, $tc, $font, $final_text);
//writes the completed image to the new folder
imagejpeg($new_im, 'new/' . $orig_text . '.jpg');
//free up resources
imagedestroy($im);
imagedestroy($new_im);
}
?>
<?php
//Allows unlimited execution time
set_time_limit(0);
//scan folder for jpg files and put them in an array
$images = glob('old/*.jpg');
//Sets font size and font file variables
$fontsize = 20;
$font = './3.ttf'; //place font in same folder as this script
//loop through array
foreach($images as $image) {
//basename create bare filename without folder/extension
$orig_text = basename($image, '.jpg');
//read current image into php resource $im that can be processed
$im = imagecreatefromjpeg($image);
//get width/height of image
$width = imagesx($im);
$height = imagesy($im);
//calculate width/height of new image adding on extra for borders
$new_width = $width + 60;
$new_height = $height + 95;
//create new image using the dimensions we've just worked out
$new_im = imagecreatetruecolor($new_width,$new_height);
//before you can use a colour, you have to define it first. uses RGB so 255, 255, 255 is white
$bg = imagecolorallocate($im, 255, 255, 255);
//fill our new image with this new colour
imagefill($new_im, 0 ,0, $bg);
//position the existing image into the new image
imagecopyresampled($new_im, $im, 30, 30, 0, 0, $width, $height, $width, $height);
//php function to caluclate width of text
$text_width = imagettfbbox($fontsize, 0, $font, $orig_text);
//define our text colour -black in this case
$tc = imagecolorallocate($im, 0, 0, 0);
//If the width of the text is greater than the width of the image, then
if($text_width[2] > $new_width)
{
//explode text at first hyphen
$lines = split(' - ', $orig_text);
//php function to re-caluclate width of text due to multiple lines
$line_1_width = imagettfbbox($fontsize, 0, $font, $lines[0]);
$line_2_width = imagettfbbox($fontsize, 0, $font, $lines[1]);
//write the text using
imagettftext($new_im, $fontsize, 0, ($new_width - $line_1_width[2]) / 2, $new_height - 40, $tc, $font, $lines[0]);
imagettftext($new_im, $fontsize, 0, ($new_width - $line_2_width[2]) / 2, $new_height - 10, $tc, $font, $lines[1]);
} else {
//else, Use the original text
$final_text = $orig_text;
//write the text using
imagettftext($new_im, $fontsize, 0, ($new_width - $text_width[2]) / 2, $new_height - 26, $tc, $font, $final_text);
}
//writes the completed image to the new folder
imagejpeg($new_im, 'new/' . $orig_text . '.jpg');
//free up resources
imagedestroy($im);
imagedestroy($new_im);
echo "FINISHED!";
}
?>