-1

I want to save my pngs, but my code does not allow me to create new pngs or overwrite the existing ones. Ideally every time the page is loaded the image would be saved.

<?php
$width = 640;
    $height = 480;  
    $font = 23;

    $string = "This is my text";
    $im = @imagecreatetruecolor($width, $height);
    imagesavealpha($im, true);
    imagealphablending($im, false);
    $white = imagecolorallocatealpha($im, 255, 255, 255, 127);
    imagefill($im, 0, 0, $white);
    $lime = imagecolorallocate($im, 0, 0, 51);
    imagettftext($im, $font, 0, 0, $font - 3, $lime, "./DroidSerif-Bold.ttf", $string);
    $im = imagecreatefrompng("test.png");
    imagedestroy($im);



?>
miken32
  • 42,008
  • 16
  • 111
  • 154
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
  • 1
    `imagecreatefrompng` doesn't *save* an image, it *loads* one... – deceze Jan 28 '16 at 15:54
  • Define `but my code does not allow me to create new pngs or overwrite the existing ones`. In what way does your code not allow that? Also you need to use `imagepng` to create a new png file. `imagecreatefrompng` creates a new image object in PHP to manipulate. – Charlotte Dunois Jan 28 '16 at 15:54

1 Answers1

4

imagecreateFROMpng as it names indicates creates an image object by reading a .PNG file. In order to save the image as a PNG, you must use the imagepng function:

...
imagettftext($im, $font, 0, 0, $font - 3, $lime, "./DroidSerif-Bold.ttf", $string);
imagepng($im, "test.png");
imagedestroy($im);
Tordek
  • 10,628
  • 3
  • 36
  • 67