Jump to content

[SOLVED] Saving Images created with GD Library


modchamp

Recommended Posts

Ok well I've got a signature generator that I use to make and allow other people to make matching signatures for a forum. Anyways it uses the GD Library and it doesn't actually save to a file, just shows the output. When I try to download the png image with IE it has me save it as a bmp, but it saves just fine. When I try in FF it let's me save it as a png, but when I open the image I saved it's something totally different, not the right image (looks like leftovers from old signatures I've made). Anyways I'm just wondering if it's possible to save these png's on the fly or if I need to have them saved temporarily to my web host. Thanks,

 

-modchamp

Yes I know that, but I'm wondering if I can have it be able to be downloaded without having to save the image to the web host. And if I did it that war, if say 2 people did it within relatively short time of each other the 1st person could very easily download the 2nd person's, so I'd want to have it throw a variable in the filename. Anyways, I just want to know if it's possible to download the image without having to save it to the web host.

I was saying, if I had it save to a filename, each time someone ran it it would overwrite that file, so therefore 2 people could download the same one. Anyways here's the gist of my code:

 

<?
header("Content-Type: image/png");
if ( $yes == "ours" ) {
If ( $raced == "Signature 1") {
$im = imagecreatefrompng("./images/01.png");
}
}
imagestring($im, $font2, $leftTextPos, $height-100, "$text", $color);
imagepng($im);
imagedestroy($im);

 

Obviously not all of my code, but that should be enough of it.

try something like

$im = imagecreate(50,50);
$bg = imagecolorallocate($im,0,0,0);
$tc = imagecolorallocate($im, 255,255,0);
imagestring($im, 5,15, 15, 'XXX', $tc);

header("content-type: application/octet-stream");
header("content-disposition: attachment; filename=x.png");
imagepng($im);
imagedestroy($im);

<a href='image.php?download=1' title='Click to download'><img src='image.php' ></a>

 

image.php

<?php
$download = isset($_GET['download'])  ? 1 : 0;

$im = imagecreate(50,50);
$bg = imagecolorallocate($im,0,0,0);
$tc = imagecolorallocate($im, 255,255,0);
imagestring($im, 5,15, 15, 'XXX', $tc);

if ($download) {
    header("content-type: application/octet-stream");
    header("content-disposition: attachment; filename=x.png");
}
else header ("content-type: image/png");

imagepng($im);
imagedestroy($im);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.