Asperon Posted August 28, 2007 Share Posted August 28, 2007 so I used GD and created a png image, and then you press a "Save" button and it runs my save.php file,this file creates the image and then uses <?php Header('Content-type: image/png'); ImagePNG($im,$location); ImageDestroy($im); ?> to save it, the image shows up in the folder, but when I view it, it is just ablack box, my image wasn't really created. I can preview the image and see that it works, is there something I am missing? and..do you need more code to help me? Quote Link to comment https://forums.phpfreaks.com/topic/67136-solved-saving-png-in-php/ Share on other sites More sharing options...
trq Posted August 28, 2007 Share Posted August 28, 2007 do you need more code to help me? Yes. Quote Link to comment https://forums.phpfreaks.com/topic/67136-solved-saving-png-in-php/#findComment-336700 Share on other sites More sharing options...
Asperon Posted August 28, 2007 Author Share Posted August 28, 2007 Here is part of my code..the images saves in teh folder, but none of the what was drawn on it saves, it just saves as the box with a black fill. <?php session_start(); if(isset($_SESSION['validUser'])){ $bgColor = $_GET['bgColor']; $logo = $_GET['logo']; $ln1[0] = $_GET['ln1_text']; $ln1[1] = $_GET['ln1_font']; $ln1[2] = $_GET['ln1_size']; $ln1[3] = $_GET['ln1_color']; $ln2[0] = $_GET['ln2_text']; $ln2[1] = $_GET['ln2_font']; $ln2[2] = $_GET['ln2_size']; $ln2[3] = $_GET['ln2_color']; $ln3[0] = $_GET['ln3_text']; $ln3[1] = $_GET['ln3_font']; $ln3[2] = $_GET['ln3_size']; $ln3[3] = $_GET['ln3_color']; $ln4[0] = $_GET['ln4_text']; $ln4[1] = $_GET['ln4_font']; $ln4[2] = $_GET['ln4_size']; $ln4[3] = $_GET['ln4_color']; $ln5[0] = $_GET['ln5_text']; $ln5[1] = $_GET['ln5_font']; $ln5[2] = $_GET['ln5_size']; $ln5[3] = $_GET['ln5_color']; function createImage($bgColor, $logo, $ln1, $ln2, $ln3, $ln4, $ln5){ //create canvas $width = 500; $height = 203; $im = ImageCreateTrueColor($width,$height); switch($bgColor){ case 'Black' : $canvas = ImageColorAllocate($im,0,0,0); break; case 'White' : $canvas = ImageColorAllocate($im,255,255,255); break; case 'Gray' : $canvas = ImageColorAllocate($im,150,150,150); break; case 'Red' : $canvas = ImageColorAllocate($im,255,0,0); break; case 'Dark Red' : $canvas = ImageColorAllocate($im,150,0,0); break; case 'Light Green' : $canvas = ImageColorAllocate($im,0,255,0); break; case 'Green' : $canvas = ImageColorAllocate($im,0,150,0); break; case 'Dark Green' : $canvas = ImageColorAllocate($im,0,100,0); break; case 'Blue' : $canvas = ImageColorAllocate($im,0,0,255); break; case 'Yellow' : $canvas = ImageColorAllocate($im,255,255,0); break; case 'Cyan' : $canvas = ImageColorAllocate($im,0,255,255); break; case 'Purple' : $canvas = ImageColorAllocate($im,150,0,150); break; case 'Violet' : $canvas = ImageColorAllocate($im,255,0,255); break; case 'Pink' : $canvas = ImageColorAllocate($im,255,100,255); break; } ImageFill($im,0,0,$canvas); //outline canvas $black = ImageColorAllocate($im,0,0,0); ImageRectangle($im,0,0,$width-1,$height-1,$black); //insert logo //Line Array // //ln[0] = text //ln[1] = font //ln[2] = size // //End Line Array //format line 1 $font = 'c:/windows/fonts/'.$ln1[1].'.ttf'; switch($ln1[3]){ case 'Black' : $color = ImageColorAllocate($im,0,0,0); break; case 'White' : $color = ImageColorAllocate($im,255,255,255); break; case 'Gray' : $color = ImageColorAllocate($im,150,150,150); break; case 'Red' : $color = ImageColorAllocate($im,255,0,0); break; case 'Dark Red' : $color = ImageColorAllocate($im,150,0,0); break; case 'Light Green' : $color = ImageColorAllocate($im,0,255,0); break; case 'Green' : $color = ImageColorAllocate($im,0,150,0); break; case 'Dark Green' : $color = ImageColorAllocate($im,0,100,0); break; case 'Blue' : $color = ImageColorAllocate($im,0,0,255); break; case 'Yellow' : $color = ImageColorAllocate($im,255,255,0); break; case 'Cyan' : $color = ImageColorAllocate($im,0,255,255); break; case 'Purple' : $color = ImageColorAllocate($im,150,0,150); break; case 'Violet' : $color = ImageColorAllocate($im,255,0,255); break; case 'Pink' : $color = ImageColorAllocate($im,255,100,255); break; } $box = ImageTTFBBox($ln1[2],0,$font,$ln1[0]); $d = $box[2] - $box[0]; $align = $width/2 - $d/2; ImageTTFText($im,$ln1[2],0,$align,45,$color,$font,$ln1[0]); // Repeats for 4 more lines... //draw some lines ImageLine($im,0,150,$width,150,$black); ImageLine($im,200,150,200,203,$black); ImageLine($im,375,150,375,203,$black); //Save to the database //this will save the path and ID number etc $link = mysql_connect('localhost', 'testUser', 'sra259') or die('Could not connect: ' . mysql_error()); mysql_select_db('iluvsocaldb') or die('Could not select database'); $userName = $_SESSION['validUser']; $query_business = "SELECT businessID FROM business WHERE userName='$userName'"; $result_business = mysql_query($query_business) or die('Query failed: '.mysql_error()); //more database code....... //where I create teh $locaton variable $query_ID = "SELECT couponID FROM coupons WHERE businessID='$businessID' AND startDate='$date'"; $result_ID = mysql_query($query_ID) or die('Query failed: '.mysql_error()); $couponID = mysql_result($result_ID,0); $location = $couponID . '.png'; $query_add = "UPDATE coupons SET location='$location' WHERE couponID='$couponID'"; $result_add = mysql_query($query_add) or die('Query failed: '.mysql_error()); //create and destroy Header('Content-type: image/png'); ImagePNG($im,$location); ImageDestroy($im); //close database mysql_close($link); }//ends create image function createImage($bgColor, $logo, $ln1, $ln2, $ln3, $ln4, $ln5); }//ends isset function else{ echo 'You are not authorized to view this page.'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67136-solved-saving-png-in-php/#findComment-336702 Share on other sites More sharing options...
Asperon Posted August 28, 2007 Author Share Posted August 28, 2007 too much code??? ??? lol Quote Link to comment https://forums.phpfreaks.com/topic/67136-solved-saving-png-in-php/#findComment-336719 Share on other sites More sharing options...
Asperon Posted August 30, 2007 Author Share Posted August 30, 2007 anyone have any answers? I'm still having difficulty, it saves the image as just a black canvas Quote Link to comment https://forums.phpfreaks.com/topic/67136-solved-saving-png-in-php/#findComment-337880 Share on other sites More sharing options...
Asperon Posted August 30, 2007 Author Share Posted August 30, 2007 I have discovered that the image will save if I do it in the update page, which is the one without any database programming, would it be the database code that is interfering? Quote Link to comment https://forums.phpfreaks.com/topic/67136-solved-saving-png-in-php/#findComment-337889 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.