Pruus Posted August 28, 2017 Share Posted August 28, 2017 I have a php code to add text on a image. Now i want to make a function to save the image, to use it several times in my code. But it does not work. function maakafbeelding($n1, $n2, $n3) { Header ("Content-type: image/jpeg"); switch ($n3): case "1": $image = imageCreateFromJPEG("images/basis-rood.jpg"); break; case "2": $image = imageCreateFromJPEG("images/blauw.jpg"); break; case "3": $image = imageCreateFromJPEG("images/infrastrutuur.jpg"); break; case "4": $image = imageCreateFromJPEG("images/park.jpg"); break; case "5": $image = imageCreateFromJPEG("images/Suteki.jpg"); break; default: $image = imageCreateFromJPEG("images/basis.jpg"); endswitch; $color = ImageColorAllocate($image, 255, 255, 255); $color1 = ImageColorAllocate($image, 169, 169, 169); // Wrtie text to horizontal alignment for the names. imagettftext($image, 70, 0, 150, 185, $color, 'font/HermesRegular.ttf', $n1); imagettftext($image, 40, 0, 500, 240, $color1, 'font/HermesRegular.ttf', $n2); // nu opslaan imagejpeg($image, 'vda-images/'.$n1.'.jpg', 80); // vernietig file in geheugen ImageDestroy($image); }.Where do i go wrong? Link to comment Share on other sites More sharing options...
gizmola Posted August 28, 2017 Share Posted August 28, 2017 You should not be outputting an image header in a script that is simply creating an image and writing it to disk. Remove the Header ("Content-type: image/jpeg"); The other thing to look into is the path: imagejpeg($image, 'vda-images/'.$n1.'.jpg', 80); Make sure that whatever process is running this php code has rights to rwx the vda-images directory. Link to comment Share on other sites More sharing options...
Pruus Posted August 28, 2017 Author Share Posted August 28, 2017 I have changed the header and it works now. Thanks. The working code: function maakafbeelding($n1, $n2, $n3) { // Header ("Content-type: image/jpeg"); switch ($n3): case "1": $image = imageCreateFromJPEG("images/basis-rood.jpg"); break; case "2": $image = imageCreateFromJPEG("images/basis-blauw.jpg"); break; case "3": $image = imageCreateFromJPEG("images/infrastructuur.jpg"); break; case "4": $image = imageCreateFromJPEG("images/park.jpg"); break; case "5": $image = imageCreateFromJPEG("images/suteki.jpg"); break; default: $image = imageCreateFromJPEG("images/basis.jpg"); endswitch; $color = ImageColorAllocate($image, 255, 255, 255); $color1 = ImageColorAllocate($image, 169, 169, 169); // Wrtie text to horizontal alignment for the names. imagettftext($image, 70, 0, 150, 185, $color, 'font/HermesRegular.ttf', $n1); imagettftext($image, 40, 0, 500, 240, $color1, 'font/HermesRegular.ttf', $n2); // nu opslaan imagejpeg($image, 'vda-images/topbanners/'.$n1.'.jpg', 80); // vernietig file in geheugen ImageDestroy($image); return; } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.