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";
}
?>

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

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);

You don't need copy, use imagejpeg.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.