desithugg Posted February 18, 2007 Share Posted February 18, 2007 I'm having some problme with php image manipulation everything works fine but the problem is when i try to output the image as a .png file it just spits the url back out. But when i change it to .jpeg or .gif it works fine the only problem is in .gif the quality is bad and in .jpeg i cant have transparent backgrounds so anyone know how i can fix that? <?php $bg = $_GET['bg']; if($bg == "") { $bg = "10"; } //trainer card background starts here $bg_file = "bg/$bg.png"; list($bg_w, $bg_h, $bg_t, $bg_a) = getimagesize($bg_file); $bg_width = 228; $bg_height = 148; $bgImage1 = imageCreateFromPNG($bg_file) or die ('failed to get the background image'); $bgImage = imageCreateTrueColor($bg_width, $bg_height) or die ('failed imageCreateTrueColor'); imageCopyResampled($bgImage, $bgImage1, 0, 0, 0, 0, $bg_width, $bg_height, $bg_w, $bg_h) or die ('failed imageCopyResampled'); //trainer card background ends here //first pokemon image starts here $poke1_x = 68; //x-admis dimensions $poke1_y = 29; //y-axis dimensions $pi1 = $_GET['poke1']; if($pi1 == "") { $pi1 = "Articuno"; } $poke1_file = "bg/pokes/$pi1.png"; list($p1_w, $p1_h, $p1_t, $p1_a) = getimagesize($poke1_file); $poke1_Image = imageCreateFromPng($poke1_file) or die ('failed to get seconed pokemon image'); $poke1_white = imageColorAllocate($poke1_Image,255,255,255); //gives the poke a white background imagecolortransparent($poke1_Image,imagecolorat($poke1_Image,0,0)); //takes off the border around the poke imagecolortransparent($poke1_Image,imagecolorat($poke1_Image,1,1)); //make the white bg of the poke transparent //first pokemon image ends here //second pokemon starts here $poke2_x = 120; //x-admis dimensions $poke2_y = 29; //y-axis dimensions $pi2 = $_GET['poke2']; if($pi2 == "") { $pi2 = "Articuno"; } $poke2_file = "bg/pokes/$pi2.png"; list($p2_w, $p2_h, $p2_t, $p2_a) = getimagesize($poke2_file); $poke2_Image = imageCreateFromPng($poke2_file) or die ('failed to get seconed pokemon image'); $poke2_white = imageColorAllocate($poke2_Image,255,255,255); // gives the poke a with background imagecolortransparent($poke2_Image,imagecolorat($poke2_Image,0,0)); //takes off the border around the poke imagecolortransparent($poke2_Image,imagecolorat($poke2_Image,1,1)); //make the white bg of the poke transparent //second pokemon ends here //third pokemon stats here $poke3_x = 172; //x-admis dimensions $poke3_y = 29; //y-axis dimensions $pi3 = $_GET['poke3']; if($pi3 == "") { $pi3 = "Articuno"; } $poke3_file = "bg/pokes/$pi3.png"; list($p3_w, $p3_h, $p3_t, $p3_a) = getimagesize($poke3_file); $poke3_Image = imageCreateFromPng($poke3_file) or die ('failed to get third pokemon image'); $poke3_white = imageColorAllocate($poke3_Image,255,255,255); // gives the poke a with background imagecolortransparent($poke3_Image,imagecolorat($poke3_Image,0,0)); //takes off the border around the poke imagecolortransparent($poke3_Image,imagecolorat($poke3_Image,1,1)); //make the white bg of the poke transparent //third pokemon ends here //fourth pokemon starts here $poke4_x = 68; //x-admis dimensions $poke4_y = 65; //y-axis dimensions $pi4 = $_GET['poke4']; if($pi4 == "") { $pi4 = "Articuno"; } $poke4_file = "bg/pokes/$pi4.png"; list($p4_w, $p4_h, $p4_t, $p4_a) = getimagesize($poke4_file); $poke4_Image = imageCreateFromPng($poke4_file) or die ('failed to get fouth pokemon image'); $poke4_white = imageColorAllocate($poke4_Image,255,255,255); // gives the poke a with background imagecolortransparent($poke4_Image,imagecolorat($poke4_Image,0,0)); //takes off the border around the poke imagecolortransparent($poke4_Image,imagecolorat($poke4_Image,1,1)); //make the white bg of the poke transparent //fouth pokemon ends here //fifth pokemon stats here $poke5_x = 120; //x-admis dimensions $poke5_y = 65; //y-axis dimensions $pi5 = $_GET['poke5']; if($pi5 == "") { $pi5 = "Articuno"; } $poke5_file = "bg/pokes/$pi5.png"; list($p5_w, $p5_h, $p5_t, $p5_a) = getimagesize($poke5_file); $poke5_Image = imageCreateFromPng($poke5_file) or die ('failed to get fifth pokemon image'); $poke5_white = imageColorAllocate($poke5_Image,255,255,255); // gives the poke a with background imagecolortransparent($poke5_Image,imagecolorat($poke5_Image,0,0)); //takes off the border around the poke imagecolortransparent($poke5_Image,imagecolorat($poke5_Image,1,1)); //make the white bg of the poke transparent //fifth pokemon ends here //sixth pokemons starts here $poke6_x = 172; //x-admis dimensions $poke6_y = 65; //y-axis dimensions $pi6 = $_GET['poke6']; if($pi6 == "") { $pi6 = "Articuno"; } $poke6_file = "bg/pokes/$pi6.png"; list($p6_w, $p6_h, $p6_t, $p6_a) = getimagesize($poke6_file); $poke6_Image = imageCreateFromPng($poke6_file) or die ('failed to get sixth pokemon image'); $poke6_white = imageColorAllocate($poke6_Image,255,255,255); // gives the poke a with background imagecolortransparent($poke6_Image,imagecolorat($poke6_Image,0,0)); //takes off the border around the poke imagecolortransparent($poke6_Image,imagecolorat($poke6_Image,1,1)); //make the white bg of the poke transparent //sixth pokemon ends here //badge #1 $badge1_x = 27; //x-admis dimensions $badge1_y = 122; //y-axis dimensions $badge1_ = $_GET['badge1']; if($badge1_ == "") { $badge1_ = "KantoBadge1"; } $badge1_file = "bg/badges/$badge1_.PNG"; list($b1_w, $b1_h, $b1_t, $b1_a) = getimagesize($badge1_file); $badge1_Image = imageCreateFromPng($badge1_file) or die ('failed to get sixth pokemon image'); $badge1_white = imageColorAllocate($badge1_Image,255,255,255); // gives the poke a with background imagecolortransparent($badge1_Image,imagecolorat($badge1_Image,0,0)); //takes off the border around the poke $badge2_x = 51; //x-admis dimensions $badge2_y = 122; //y-axis dimensions $badge2_ = $_GET['badge2']; if($badge2_ == "") { $badge2_ = "KantoBadge1"; } $badge2_file = "bg/badges/$badge2_.PNG"; list($b2_w, $b2_h, $b2_t, $b2_a) = getimagesize($badge2_file); $badge2_Image = imageCreateFromPng($badge2_file) or die ('failed to get sixth pokemon image'); $badge2_white = imageColorAllocate($badge2_Image,255,255,255); // gives the poke a with background imagecolortransparent($badge2_Image,imagecolorat($badge2_Image,0,0)); //takes off the border around the poke $badge3_x = 75; //x-admis dimensions $badge3_y = 122; //y-axis dimensions $badge3_ = $_GET['badge3']; if($badge3_ == "") { $badge3_ = "KantoBadge1"; } $badge3_file = "bg/badges/$badge3_.PNG"; list($b3_w, $b3_h, $b3_t, $b3_a) = getimagesize($badge3_file); $badge3_Image = imageCreateFromPng($badge3_file) or die ('failed to get sixth pokemon image'); $badge3_white = imageColorAllocate($badge3_Image,255,255,255); // gives the poke a with background imagecolortransparent($badge3_Image,imagecolorat($badge3_Image,0,0)); //takes off the border around the poke $badge4_x = 99; //x-admis dimensions $badge4_y = 122; //y-axis dimensions $badge4_ = $_GET['badge4']; if($badge4_ == "") { $badge4_ = "KantoBadge1"; } $badge4_file = "bg/badges/$badge4_.PNG"; list($b4_w, $b4_h, $b4_t, $b4_a) = getimagesize($badge4_file); $badge4_Image = imageCreateFromPng($badge4_file) or die ('failed to get sixth pokemon image'); $badge4_white = imageColorAllocate($badge4_Image,255,255,255); // gives the poke a with background imagecolortransparent($badge4_Image,imagecolorat($badge4_Image,0,0)); //takes off the border around the poke $badge5_x = 123; //x-admis dimensions $badge5_y = 122; //y-axis dimensions $badge5_ = $_GET['badge5']; if($badge5_ == "") { $badge5_ = "KantoBadge1"; } $badge5_file = "bg/badges/$badge5_.PNG"; list($b5_w, $b5_h, $b5_t, $b5_a) = getimagesize($badge5_file); $badge5_Image = imageCreateFromPng($badge5_file) or die ('failed to get sixth pokemon image'); $badge5_white = imageColorAllocate($badge5_Image,255,255,255); // gives the poke a with background imagecolortransparent($badge5_Image,imagecolorat($badge5_Image,0,0)); //takes off the border around the poke $badge6_x = 147; //x-admis dimensions $badge6_y = 122; //y-axis dimensions $badge6_ = $_GET['badge6']; if($badge6_ == "") { $badge6_ = "KantoBadge1"; } $badge6_file = "bg/badges/$badge6_.PNG"; list($b6_w, $b6_h, $b6_t, $b6_a) = getimagesize($badge6_file); $badge6_Image = imageCreateFromPng($badge6_file) or die ('failed to get sixth pokemon image'); $badge6_white = imageColorAllocate($badge6_Image,255,255,255); // gives the poke a with background imagecolortransparent($badge6_Image,imagecolorat($badge6_Image,0,0)); //takes off the border around the poke $badge7_x = 171; //x-admis dimensions $badge7_y = 122; //y-axis dimensions $badge7_ = $_GET['badge7']; if($badge7_ == "") { $badge7_ = "KantoBadge1"; } $badge7_file = "bg/badges/$badge7_.PNG"; list($b7_w, $b7_h, $b7_t, $b7_a) = getimagesize($badge7_file); $badge7_Image = imageCreateFromPng($badge7_file) or die ('failed to get sixth pokemon image'); $badge7_white = imageColorAllocate($badge7_Image,255,255,255); // gives the poke a with background imagecolortransparent($badge7_Image,imagecolorat($badge7_Image,0,0)); //takes off the border around the poke $badge8_x = 195; //x-admis dimensions $badge8_y = 122; //y-axis dimensions $badge8_ = $_GET['badge8']; if($badge8_ == "") { $badge8_ = "KantoBadge1"; } $badge8_file = "bg/badges/$badge8_.PNG"; list($b8_w, $b8_h, $b8_t, $b8_a) = getimagesize($badge8_file); $badge8_Image = imageCreateFromPng($badge8_file) or die ('failed to get sixth pokemon image'); $badge8_white = imageColorAllocate($badge8_Image,255,255,255); // gives the poke a with background imagecolortransparent($badge8_Image,imagecolorat($badge8_Image,0,0)); //takes off the border around the poke //badge #1 end //trainer sprite starts here $trainer_x = 1; //x-admis dimensions $trainer_y = 30; //y-axis dimensions $trainer = $_GET['trainer']; if($trainer == "") { $trainer = "dptr000"; } $trainer_file = "bg/trainers/$trainer.png"; list($t_w, $t_h, $t_t, $t_a) = getimagesize($trainer_file); $trainer_Image = imageCreateFromPng($trainer_file) or die ('failed to get trainer pokemon image'); $trainer_white = imageColorAllocate($trainer_Image,255,255,255); // gives the poke a with background imagecolortransparent($trainer_Image,imagecolorat($trainer_Image,0,0)); //takes off the border around the poke //trainer sprite ends here //merging the stupid images starts here imageCopyMerge($bgImage, $poke1_Image, $poke1_x, $poke1_y, 0, 0, $p1_w, $p1_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $poke2_Image, $poke2_x, $poke2_y, 0, 0, $p2_w, $p2_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $poke3_Image, $poke3_x, $poke3_y, 0, 0, $p3_w, $p3_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $poke4_Image, $poke4_x, $poke4_y, 0, 0, $p4_w, $p4_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $poke5_Image, $poke5_x, $poke5_y, 0, 0, $p5_w, $p5_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $poke6_Image, $poke6_x, $poke6_y, 0, 0, $p6_w, $p6_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $badge1_Image, $badge1_x, $badge1_y, 0, 0, $b1_w, $b1_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $badge2_Image, $badge2_x, $badge2_y, 0, 0, $b2_w, $b2_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $badge3_Image, $badge3_x, $badge3_y, 0, 0, $b3_w, $b3_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $badge4_Image, $badge4_x, $badge4_y, 0, 0, $b4_w, $b4_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $badge5_Image, $badge5_x, $badge5_y, 0, 0, $b5_w, $b5_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $badge6_Image, $badge6_x, $badge6_y, 0, 0, $b6_w, $b6_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $badge7_Image, $badge7_x, $badge7_y, 0, 0, $b7_w, $b7_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $badge8_Image, $badge8_x, $badge8_y, 0, 0, $b8_w, $b8_h, 100) or die ('failed imageCopyMerge'); imageCopyMerge($bgImage, $trainer_Image, $trainer_x, $trainer_y, 0, 0, $t_w, $t_h, 100) or die ('failed imageCopyMerge'); //merging the images ends here //add text to image starts here $text_white = imagecolortransparent($bgImage,imagecolorat($bgImage,0,0)); $text = $_GET['text']; if($text == "") { $text = "Desithugg"; } $font = 'bg/tcardfont.ttf'; $fontSize = "10"; $fontRotation = "0"; ImageTTFText($bgImage, $fontSize, $fontRotation, 133, 24, $text_white, $font, $text); //add text to image ends here //displaying the image starts here imagecolortransparent($bgImage,imagecolorat($bgImage,2,2)); //takes off the border around the poke header("Content-Type: image/jpeg"); imagejpeg($bgImage,'',100) or die ('failed to make the trainer card'); //displaying the image ends here ?> thats my code the only simple change i make to it is change the end header("Content-Type: image/jpeg"); imagejpeg($bgImage,'',100) or die ('failed to make the trainer card'); to header("Content-Type: image/png"); imagepng($bgImage,'',100) or die ('failed to make the trainer card'); Link to comment https://forums.phpfreaks.com/topic/39034-php-image-manipulation-problem/ Share on other sites More sharing options...
kenrbnsn Posted February 18, 2007 Share Posted February 18, 2007 Please post your code between tags. Ken Link to comment https://forums.phpfreaks.com/topic/39034-php-image-manipulation-problem/#findComment-187982 Share on other sites More sharing options...
desithugg Posted February 18, 2007 Author Share Posted February 18, 2007 there i posted the code Link to comment https://forums.phpfreaks.com/topic/39034-php-image-manipulation-problem/#findComment-187985 Share on other sites More sharing options...
desithugg Posted February 18, 2007 Author Share Posted February 18, 2007 any idea guys here are the two files http://pca.x3teamz.net/menu.php //.jpg file http://pca.x3teamz.net/menu2.php //.png file the only difference in the code between the two is one has header("Content-Type: image/jpeg"); imagejpeg($bgImage,'',100) or die ('failed to make the trainer card'); the other has header("Content-Type: image/png"); imagepng($bgImage,'',100) or die ('failed to make the trainer card'); but the seconed one .png just spits the url back out instead of the image Link to comment https://forums.phpfreaks.com/topic/39034-php-image-manipulation-problem/#findComment-188080 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.