Jump to content

Gd help


Lassie

Recommended Posts

Is it possible to both save and display a created image?

I can display but not save

 

 

<?php
$str2=$_GET['str'];
$str=$_GET['str1'];
$str3="By";
$ourFileName = $_SERVER['DOCUMENT_ROOT'] . '/images/test.png';

$image = ImageCreateFromPNG("http://localhost:8888/wordpress_3/wp-content/plugins/Authors2/jackets/GDL.png");
$color = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$colorShadow = imagecolorallocate($image, 0x66, 0x66, 0x66);
$font = 'Tahoma.ttf';
$fontSize = "10";
$fontRotation = "0";

/* Shadow str = title */
ImageTTFText($image, $fontSize, $fontRotation, 27, 22, $colorShadow, $font, $str );

/* Top Level */
ImageTTFText($image, $fontSize, $fontRotation, 25, 20, $color, $font, $str);

/*standard narrative*/
ImageTTFText($image, $fontSize, $fontRotation, 25, 60, $color, $font, $str3);

ImageTTFText($image, $fontSize, $fontRotation, 25, 100, $color, $font, $str2);


header("Content-Type: image/PNG");
ImagePng ($image);
imagedestroy($image);
?>

Link to comment
Share on other sites

You can use second parameter to save the image like

$path ='images/imagename.png';
ImagePng ($image,$path);

 

also if you want to force download image then use headers

header('Content-Disposition: Attachment;filename=imagename.png');
header('Content-type: image/png'); 

Link to comment
Share on other sites

Thank you.

I can get the image with the text, but when i add the save path the image does not show, just a small question mark in a box.

I cant see where this is going wrong.

My code

is

<?php
$str2=$_GET['str'];
$str=$_GET['str1'];
$str3="By";

$path ='http://localhost:8888/test_upload/images/imagename.png';

$image = ImageCreateFromPNG("http://localhost:8888/wordpress_3/wp-content/plugins/Authors2/jackets/GDL.png");
$color = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$colorShadow = imagecolorallocate($image, 0x66, 0x66, 0x66);
$font = 'Tahoma.ttf';
$fontSize = "10";
$fontRotation = "0";

/* Shadow str = title */
ImageTTFText($image, $fontSize, $fontRotation, 27, 22, $colorShadow, $font, $str );

/* Top Level */
ImageTTFText($image, $fontSize, $fontRotation, 25, 20, $color, $font, $str);

/*standard narrative*/
ImageTTFText($image, $fontSize, $fontRotation, 25, 60, $color, $font, $str3);

ImageTTFText($image, $fontSize, $fontRotation, 25, 100, $color, $font, $str2);

header('Content-Disposition: Attachment;filename=imagename.png');
header("Content-Type: image/PNG");

ImagePng ($image,$path);

imagedestroy($image);
?>

and the img tag is

echo "<img src='http://localhost:8888/test_upload/image-save.php?str=$str&str1=$str1'/>";

Any advice appreciated.

Link to comment
Share on other sites

if you want to display image on browser then remove this line from your code

header('Content-Disposition: Attachment;filename=imagename.png');

 

by removing this code your image will saved at the location you specified and also displayed on browser but it will not downloaded automatically to download image you should right click on image and then coose "save image as " option

Link to comment
Share on other sites

try this code

 

<?php
ob_start();
$str2=$_GET['str'];
$str=$_GET['str1'];
$str3="By";

$path ='http://localhost:8888/test_upload/images/imagename.png';

$image = ImageCreateFromPNG("http://localhost:8888/wordpress_3/wp-content/plugins/Authors2/jackets/GDL.png");
$color = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$colorShadow = imagecolorallocate($image, 0x66, 0x66, 0x66);
$font = 'Tahoma.ttf';
$fontSize = "10";
$fontRotation = "0";

/* Shadow str = title */
ImageTTFText($image, $fontSize, $fontRotation, 27, 22, $colorShadow, $font, $str );

/* Top Level */
ImageTTFText($image, $fontSize, $fontRotation, 25, 20, $color, $font, $str);

/*standard narrative*/
ImageTTFText($image, $fontSize, $fontRotation, 25, 60, $color, $font, $str3);

ImageTTFText($image, $fontSize, $fontRotation, 25, 100, $color, $font, $str2);

//header('Content-Disposition: Attachment;filename=imagename.png');
//header("Content-Type: image/PNG");

ImagePng ($image,$path);

imagedestroy($image);


if ($fd = fopen (Path, "r")) 
{
header("Content-Type: image/PNG");
//header("Content-Disposition: attachment; filename=".$n);
//header("Cache-control: private");
 while(!feof($fd)) 
	{
        $buffer = fread($fd, 2048);
        echo $buffer;
	}

}
fclose ($fd);
ob_end_flush();
exit;

?>

Link to comment
Share on other sites

I still cant save the image.

I need it to be automatically saved rather than a forced download as I need the generated image saved to  the server and placed in a user refernced.

For information this is being developed on a mac.

Could you explain what you were intending with the code you posted to read the file please?

if ($fd = fopen (Path, "r")) 
   {
   header("Content-Type: image/PNG");
   //header("Content-Disposition: attachment; filename=".$n);
   //header("Cache-control: private");
    while(!feof($fd)) 
      {
        $buffer = fread($fd, 2048);
        echo $buffer;
      }
   
   }
fclose ($fd);
   ob_end_flush();
   exit;

?>

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.