Jump to content

email an image made on the fly?


halfasleeps

Recommended Posts

ok i have php page that generates an image called hidalgoImager.php and on another page I want to use PHPMailer to email a copy of the image.

 

the image generating page works but I cant seem to send it in an email.

....is there a way to do this?

 

Any help is apreciated...THANKS!!

 

 

heres my code on the emailing page:

<?php
session_start();

$_SESSION["HIDALGO_IMAGE_PIXELS"] = explode("|",$_POST['pixels']);
$_SESSION["HIDALGO_IMAGE_WIDTH"] = $_POST['width'];
$_SESSION["HIDALGO_IMAGE_HEIGHT"] = $_POST['height'];

//print_r($_POST);

//echo "<br><br><br>Pixels:<br>".print_r($_SESSION["HIDALGO_IMAGE_PIXELS"]).'<br>';

require_once("../class.phpmailer.php");

$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->From = "jisaacks@kranichs.com";
$mail->AddAddress("halfasleeps@gmail.com, jisaacks@kranichs.com"); 
$mail->Subject = "Hidalgo Image";
$mail->AddEmbeddedImage("hidalgoImager.php", "hidalgo_band", "hidalgo_band.png");
$mail->Body = 'Embedded Image: <img alt="PHPMailer" src="cid:hidalgo_band"> Here is an image!'; 
$mail->Send();

echo '<META HTTP-EQUIV="Refresh" CONTENT="0;URL=hidalgo_view_image.php">';

?>

 

heres my code on hidalgoImager.php:

<?php
session_start();

function getRGBChannels ($hex) {

$difference = 6 - strlen($hex);
for($i = 0; $i<$difference; $i++) {
	$hex = "0".$hex;
}
$R = substr($hex,0,2);
$G = substr($hex,2,2);
$B = substr($hex,4,2);

// get decimal color values for R G B
$R = hexdec($R);
$G = hexdec($G);
$B = hexdec($B);

return array("R" => $R, "G" => $G, "B" => $B);
}

$pixels = array ("FFFFFF", "FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF", "00FFFF", "000000", "FFFFFF", "FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF", "00FFFF", "000000");

$x = 4;
$y = 4;


if(isset($_SESSION["HIDALGO_IMAGE_PIXELS"])){
$pixels = $_SESSION["HIDALGO_IMAGE_PIXELS"];
$x = $_SESSION["HIDALGO_IMAGE_WIDTH"];
$y = $_SESSION["HIDALGO_IMAGE_HEIGHT"];
}


$gd = imagecreatetruecolor($x, $y);


$pixel = 0;
for($i = 0; $i<$y; $i++){
for($j = 0; $j<$x; $j++){
	$nextPixel = getRGBChannels($pixels[$pixel]);
	imagesetpixel($gd, $j,$i, imagecolorallocate($gd, $nextPixel["R"], $nextPixel["G"], $nextPixel["B"]) );
	$pixel++;
}
} 

header('Content-Type: image/png');
imagepng($gd);

?> 

Link to comment
Share on other sites

Thank you very much for your reply.

 

so I do have to save it?

thats one thing I was wondering because over time saving all the images could take up alot of server space.

 

maybe there is a way I can save it, then delete it after its done being used?

 

can you please point me to somewhere that will explain how to save/delete the image?

 

Thank you!

Link to comment
Share on other sites

or email a link to the image and let the recipient save it

 

I dont think theres a way to do this because the image being created is based on variables from an application. Basically I have a design your own ring application which is flash, and I want to be able to email them an image of the ring they designs, and be able to use an image of the ring they designed in the shopping cart if they decide to buy it. so after they leave the page, trying to access the script to that generates the image would fail.

 

I think I am good just saving it and then deleting it when I am done. ofcourse I would have to not delete it until they hit the reciept page, so they can see an image of it in their cart. but then I dont know how I would handle deleting it if the user just closes the browser without hitting the receipt page. hmm...

 

I was going to mark this thread resolved but I am not seeing the option.

 

Thanks Guys!!!!!!!!!

Link to comment
Share on other sites

I always do my dynamic images using query strings to pass the parameters

 

<img src="myimage.php?var1=x&var2=y&var3=z">

 

If you do it that way it's easy to send the llink.

 

Unfortuntely the variable I am using is a list of all the pixels for the image which is way to long for a URL query like that. But thats the only way I know of to get the image data from Flash to PHP.

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.