SapAuthor Posted August 17, 2007 Share Posted August 17, 2007 I'm working on a big project building a SOAP grind shoe "builder game" In the past there a was one which was in shockwave. I am rebuiding it in flash. one feature was you could click a button and get your shoe that you made sent to you in an email (also emailed to the website owner to post it). I have a screenshot flash function, and a php script that takes the screen shot (in the form of a very large text variable) and complies it, allowing me to "imagegif($img);" it (where $img is the compiled image variable). I also found an email with attachment script. Now it attaches the file with this code: (or mainly) $fileatt = ""; //Path to the File $fileatt_type = "application/octet-stream"; //File Type $fileatt_name = ""; //Filename of attachment. How do i turn the $img variable into an actual image (like something.gif) and assign it to the $fileatt variable? If i just put "$fillatt = $img;" it will probably just attach a large text file. Any ideas? this is the final step, after i have this i can finish my project. Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/ Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 try this (untested) <?php //**** //you have this part but for referance i included it //$imgname = "image.gif"; //$img = imagecreatefromgif($imgname); //**** // NOTE: that $img is the image resource $filename = 'temp.gif'; if (is_writable($filename)) { if (!$handle = fopen($filename, 'w+')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, imagejpeg($img)) === FALSE) { echo "Cannot write to file ($filename)"; exit; } fclose($handle); } else { echo "The file $filename is not writable"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/#findComment-326931 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 if you have php5 then try file_put_contents ( "temp.gif", $img); Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/#findComment-326935 Share on other sites More sharing options...
SapAuthor Posted August 17, 2007 Author Share Posted August 17, 2007 I do'nt really get that. I have a string variable of the 'image'. I need to know how to turn that into a gif and assign it to a variable :-/ i searched the various image variables but couldn't find anything that helps. I'm still pretty noobish to php, but is the code you are talking i should put in the: //$imgname = "image.gif"; //$img = imagecreatefromgif($imgname); becuase if it is, why did you have it "//"ed, and if i put that code in there, will it make $imgname the gif image, or make $img an actual gif image in the variable? okay, the file_put_contents may work, but how do i first change the bitmap $img into a gif compression? is it the imagecreatefromstring? Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/#findComment-326945 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 okay, the file_put_contents may work, but how do i first change the bitmap $img into a gif compression? is it the imagecreatefromstring? Ermm both post would do the same thing!! i assumes you created the image resource and wanted to put it into a file for emailing! the i commented out the //$imgname = "image.gif"; //$img = imagecreatefromgif($imgname); was to show the creation of the image resource! whats is $img ? exactly how did you generate it Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/#findComment-326951 Share on other sites More sharing options...
SapAuthor Posted August 17, 2007 Author Share Posted August 17, 2007 Here's my code for the image creation alone: <?php error_reporting(0); /** * Get the width and height of the destination image * from the POST variables and convert them into * integer values */ $w = (int)$_POST['width']; $h = (int)$_POST['height']; // create the image with desired width and height $img = imagecreatetruecolor($w, $h); // now fill the image with blank color // do you remember i wont pass the 0xFFFFFF pixels // from flash? imagefill($img, 0, 0, 0xFFFFFF); $rows = 0; $cols = 0; // now process every POST variable which // contains a pixel color for($rows = 0; $rows < $h; $rows++){ // convert the string into an array of n elements $c_row = explode(",", $_POST['px' . $rows]); for($cols = 0; $cols < $w; $cols++){ // get the single pixel color value $value = $c_row[$cols]; // if value is not empty (empty values are the blank pixels) if($value != ""){ // get the hexadecimal string (must be 6 chars length) // so add the missing chars if needed $hex = $value; while(strlen($hex) < 6){ $hex = "0" . $hex; } // convert value from HEX to RGB $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); // allocate the new color // N.B. teorically if a color was already allocated // we dont need to allocate another time // but this is only an example $test = imagecolorallocate($img, $r, $g, $b); // and paste that color into the image // at the correct position imagesetpixel($img, $cols, $rows, $test); } } } // print out the correct header to the browser header("Content-type:image/jpeg"); // display the image imagegif ($img); ?> So, are you saying to put the STRING raw image data that's in "$img" into a gif string, i should do: $imageingifcompression = imagecreatefromstring ($img); Then i can use the "$imageingifcompression" in my email function as the attachment? Oh and thanks again for your patients and help, i understand that i'm a bit slow on catching on. Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/#findComment-326955 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 OK first thats a kinda weird header of a JPEG!.. in anycase change // print out the correct header to the browser header("Content-type:image/jpeg"); // display the image imagegif ($img); to // print out the correct header to the browser //header("Content-type:image/jpeg"); // display the image imagegif ($img,"temp.gif"); should create a file temp.gif Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/#findComment-326960 Share on other sites More sharing options...
SapAuthor Posted August 17, 2007 Author Share Posted August 17, 2007 Okay, got that, now how do i attach the file to the email? i found a simpler email script, here it is: # To Email Address $emailaddress="to@address.com"; # From Email Address $fromaddress = "from@address.com"; # Message Subject $emailsubject="This is a test mail with some attachments"; # Use relative paths to the attachments $attachments = Array( Array("file"=>"../../test.doc", "content_type"=>"application/msword"), Array("file"=>"../../123.pdf", "content_type"=>"application/pdf") ); # Message Body $body="This is a message with <b>".count($attachments)."</b> attachments and maybe some <i>HTML</i>!"; send_mail($emailaddress, $fromaddress, $emailsubject, $body, $attachments); ?> Or if that won't work, just how do i then send it? Since the file may be created, but i don't know where it is to grab it and send it. *edit* also, the send_mail function won't work on my server, i guess i don't have that high of php? the mail function does. The server i'm switching to next week does have php 5. Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/#findComment-326964 Share on other sites More sharing options...
MadTechie Posted August 17, 2007 Share Posted August 17, 2007 try using phpmailer, Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/#findComment-327017 Share on other sites More sharing options...
SapAuthor Posted August 17, 2007 Author Share Posted August 17, 2007 Okay, but that still doesn't solve the problem of getting the image to the attachment. Maybe this will make it easier, i've been trying for hours to find code to do this, how do i take that long bitmap variable and convert it into a gif image and save it to my server? If i did that, then i could just run the email script and point the attachment to that file location. Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/#findComment-327030 Share on other sites More sharing options...
SapAuthor Posted August 17, 2007 Author Share Posted August 17, 2007 Okay, problem solved. I didn't have the folder chmod 777, so the imagegif wouldn't work. I just tested it out, i created the image successfully, now i can just point to that file with the attach email function. phew... i'm sorry for all the trouble, thanks so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/65478-solved-problems-sending-image-in-email-script-thanks-for-any-help/#findComment-327065 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.