0

Here is a PHP code that writes a string on the bottom of a given image. I want to have the image with the string on it to be saved in a folder. The problem is that this script copies the image without the stamped text. Here is the code:

<?php
$imag = "images/5.jpg";
//text to display
$text = "http://www.sitename.com";
//dimensions
$wh = getimagesize($imag);
$width = $wh[0];
$height = $wh[1];
//call image
$im = imageCreateFromJpeg($imag);
//RGB color call and shadow call
$color = imageColorAllocate($im,255,255,255);
$shadow = imageColorAllocate($im,128,128,128);
//assign font
$font = 'arial.ttf';
//assign size
$size = round($width/30);
//shadow param
$xs = ($width * 0.62);
$ys = ($height * 0.98);
//get text startpoints and angle
$x = ($width * 0.61);
$y = ($height * 0.977);
$angle = 30;
//write shadow
imagettftext($im,$size,$angle,$xs,$ys,$shadow,$font,$text);
//write string
imagettftext($im,$size,$angle,$x,$y,$color,$font,$text);
//assign JPG type
Header("Content-type: image/jpg");
//create JPG
imageJpeg($im);
//clear memory
imageDestroy($im);
//Save in folder
$newfile = "images/55.jpg";
$oldfile = $imag;
if (!copy($oldfile, $newfile)) {
	echo "failed to copy $oldfile...\n";
}
?>

Edited by george61: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by pritaeas
0

1. Use lowercase function names.
2. imagejpeg has a filename parameter, use that to overwrite your original image.

0

Still not working this code isn't able of creating a copy

//create JPG
imagejpeg($im);
//copy
$oldfile = $im;
$newfile = "images/56.jpg";
if (!copy($oldfile, $newfile)) {
	echo "failed to copy...\n";
}
//clear memory
imageDestroy($im);

Edited by george61: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.