Jump to content

image create with gd lib, save output


hyster
Go to solution Solved by scootstah,

Recommended Posts

this code works fine apart from it displays the image in the browser, what id like to happen is to have the image save to a folder, I don't understand all the code so I don't no what im looking for

<?php
$name = 'Hyster';


$img=imagecreatetruecolor(180,20);
imagealphablending($img,false);

$col=imagecolorallocatealpha($img,255,255,255,127);
imagefilledrectangle($img,0,0,180,20,$col);
imagealphablending($img,true);

$font=$_SERVER["DOCUMENT_ROOT"].'./Arial.ttf';
$color = imagecolorallocate($img, 0, 0, 0);
imagettftext($img,11,0,5,14,$color,$font,$name); 

header('Content-Type: image/png');
imagealphablending($img,false);
imagesavealpha($img,true);
imagepng($img);

exit;
?>
Link to comment
Share on other sites

just come across another issue lol.

I cant use any html when using the code, I want to redirect after the code runs.

if I put the code into the php it still outputs as plain text not html

<meta http-equiv='refresh' content='5; url=./png.php?name=$nick' />
<?php
$name = $_GET['name'];

$img=imagecreatetruecolor(180,20);
imagealphablending($img,false);

$col=imagecolorallocatealpha($img,255,255,255,127);
imagefilledrectangle($img,0,0,180,20,$col);
imagealphablending($img,true);

$font=$_SERVER["DOCUMENT_ROOT"].'./Arial.ttf';
$color = imagecolorallocate($img, 0, 0, 0);
imagettftext($img,11,0,5,14,$color,$font,$name); 

header('Content-Type: image/png');
imagealphablending($img,false);
imagesavealpha($img,true);
imagepng($img, "./img/name/$name.png");
imagedestroy($img);
?>
Link to comment
Share on other sites

thanks again scootstah, ur a star :D

 

just encase any1 else has need for this , this is my final code to create a transparent png overlaid with text, rotate 90 deg and save to a folder

<?php

$nick = 'some source';

$img=imagecreatetruecolor(100,20);
imagealphablending($img,false);

$col=imagecolorallocatealpha($img,255,255,255,127);
imagefilledrectangle($img,0,0,180,20,$col);
imagealphablending($img,true);

$degrees = 90; //rotate image
$font=$_SERVER["DOCUMENT_ROOT"].'./Arial.ttf';
$color = imagecolorallocate($img, 0, 0, 0);
imagettftext($img,11,0,5,14,$color,$font,$nick); 

imagealphablending($img,false);
imagesavealpha($img,true);
$img1 = imagerotate($img, $degrees, 0);
imagepng($img1, "./img/name/$nick.png");
imagedestroy($img);

?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.