PHP - Php Gd And Transparency Problem
I have a transparency color set up with my GD script. It makes the image semi transparent with an ugly border. Any tips or Hints?
Page: http://www.zeldadungeon.net/Justin/miniheros/test.php Code: [Select] <? $bg = imagecreatefrompng('http://i241.photobucket.com/albums/ff279/tiger_leo/reddraft.png'); $color = imagecolorallocate($bg, 168, 97, 97); $font = './BOOKOS.TTF'; $insert = imagecreatefrompng('http://i241.photobucket.com/albums/ff279/tiger_leo/heartdraft.png'); imagealphablending($insert, true); imagesavealpha($insert, true); $xOffset = 20; $yOffset = 20; imagecolortransparent($insert, $color); $insert_x = imagesx($insert); $insert_y = imagesy($insert); header('Content-Type: image/png'); imagecopymerge($bg,$insert,$xOffset,$yOffset,0,0,$insert_x,$insert_y,100); imagepng($bg); imagedestroy($bg); ?> Similar TutorialsSo I wanted to preserve the transparency on a circle shaped .png file. I figured the best way to do this was to fill the background in with some particular color and then use imagecolortransparent() to hide the color. Using code found he http://www.php.net/manual/en/function.imagecolortransparent.php I tried to do just this. I kept getting errors and so to isolate the problem I made a new file and copied the original code: Code: [Select] <?php // Create a 55x30 image $im = imagecreatetruecolor(55, 30); $red = imagecolorallocate($im, 255, 0, 0); $black = imagecolorallocate($im, 0, 0, 0); // Make the background transparent imagecolortransparent($im, $black); // Draw a red rectangle imagefilledrectangle($im, 4, 4, 50, 25, $red); // Save the image imagepng($im, './imagecolortransparent.png'); imagedestroy($im); ?>This still didn't work : Warning: imagepng() [function.imagepng]: Unable to open './imagecolortransparent.png' for writing: Permission denied in /Library/WebServer/Documents/temp/test.php on line 21 So I deleted './imagecolortransparent.png' and got: �PNG IHDR7�tRNSn��AIDATX���1 �����l�.B�Er[�DH���⦞�^r��x���%�K��/9^r�����U,ҟ� IEND�B`� IDK what to do, can someone explain what is wrong or what other method I can use to preserve the transparency of the .png? Hey guys i am currently working on a thumbnail script. The idea is to be able to resize any image on the fly by adding some parameters to the images url ex: thisimage.jpg~160x160 It's then picked up by an htaccess rule that sends it to a php script that resize the image and returns it using the GD library. The script is working great but got a problem keeping the transparency with PNG images ... What ever i do the resized image has a black background. I tryed all sorts of things but it's just not working ... can anybody help me understand where i got it wrong? // [......] // Create output image $outImg = imagecreate ($outWidth, $outHeight); // Load src image switch($srcType) { case "png": $srcImg = imagecreatefrompng($uri); $background = imagecolorallocate($srcImg, 255, 255, 255); imagecolortransparent($srcImg, $background); imagealphablending($srcImg, true); imagesavealpha($srcImg, true); break; case "gif": $srcImg = imagecreatefromgif($uri); break; case "jpeg": $srcImg = imagecreatefromjpeg($uri); break; default: diewith("unsupported file type '$uri'"); }; // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); // [......] Hey guys i have a script that create thumnail version of any JPG, PNG, GIF images. It works great but the only problem is it's not keeping the transparency. It adds a black background instead. I made a very big search and tryed at least 100 things and i keep gething the black background ... This is the original image with the transparancy: This is the image after it's passed in the thumnail script: <?php // ... // Create output image $outImg = imagecreatetruecolor ($outWidth, $outHeight); // Load src image switch($srcType) { case "png": $srcImg = imagecreatefrompng($uri); $background = imagecolorallocate($srcImg, 255, 255, 255); imagecolortransparent($srcImg, $background); imagealphablending($srcImg, true); imagesavealpha($srcImg, true); break; case "gif": $srcImg = imagecreatefromgif($uri); break; case "jpeg": $srcImg = imagecreatefromjpeg($uri); break; default: diewith("unsupported file type '$uri'"); }; // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); // Save to cached thumb switch($srcType) { case "png": $res = imagepng($outImg, $cacheFile); break; case "gif": $res = imagegif($outImg, $cacheFile); break; case "jpeg": $res = imagejpeg($outImg, $cacheFile); break; default: diewith("unsupported file type '$uri'"); } //... ?> I am working with the GD Library, and I was wondering if anyone knew of a function or a way to set the transparency of a GD image (Not the final image) What I am doing is taking an jpg image as the bottom image, then I would like to place a jpg image on top of it with 50 transparency, then flatten the image as a jpg. I can not find anything on this, only information on setting png alpha values. I am having difficulty keeping transparency on my png resizing function. I have searched all around and tried various solutions. However, all I keep getting is a black background. Everything else about the function is working fine. Any help would be appreciated. Here is the code for transparency that isn't working: Code: [Select] $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagealphablending($dst_img,false); imagesavealpha($dst_img,true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $transparent); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); Here is the full function code: Code: [Select] function createthumb($name,$filename,$new_w,$new_h) { $system=explode(".",$name); if (preg_match("/jpg|jpeg/",$system[1])) { $src_img=imagecreatefromjpeg($name); } if (preg_match("/png/",$system[1])) { $src_img=imagecreatefrompng($name); } $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagealphablending($dst_img,false); imagesavealpha($dst_img,true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $transparent); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if (preg_match("/png/",$system[1])) { imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); } I have the below code that outputs my image correctly expect it puts a black background in it, instead of keeping it transparent. I'm tried using imagealphablending and couldn't get it to work. What should I use to get it to work correctly and where should I put it. $src = imagecreatefrompng($target); echo $scr; list($width,$height)=getimagesize($target); $newwidth=54; // new width of image $newheight=54; $tmp=imagecreatetruecolor($newwidth,$newheight); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); $image1 = imagecreatefrompng('Surround.png'); imagecopymerge($image1, $tmp, 5, 5, 0, 0, 54, 54, 100); This is what my gd script output looks like, the black needs to be transparent I would like to select a color that isn't in an image, any thoughts on the best way? Maybe this isn't even the best way to do this. I am using imagerotate, and for the 3rd parameter, I would like the uncovered area to be transparent. I have done this, but I had to use a color then make every color in the image of that color transparent. so, either what is the best way: A. Is there a good way to do this? B. save every pixel color in an array then loop though the array testing colors that are not in the array and setting that as the transparent value. C. Other. What? So basically I have two lines that generate an image from png and then preserve the transparency of said png. Code: [Select] $bub1 = imagecreatefrompng ("Energy/$energy1b.png"); imageSaveAlpha($bub1, true);This works by itself when generating just this image. But when combined with another image: Code: [Select] imagecopymerge($image, $bub1, 680, 40, 0, 0, 50, 50, 100);It fills in the back ground around the image and the transparency is not preserved. Why is this and how can i fix it? Im trying to make a script that previews the level for a game, but im having issues with transparency and the rotation of each image. you can see the problem he http://beta.trackmill.com/DUI/preview/ here is the php file <?php header('Content-Type: image/png'); $image = imagecreatefrompng('images/Background.png'); function radiansToDegrees($radians) { return $radians * 180 / pi(); } $map = file_get_contents('map.txt'); $blocks = split("<obj", $map); for($i=2; $i<count($blocks); $i++) { $arg = split(" ", $blocks[$i]); $n = str_replace("n", "", str_replace("=", "", str_replace('"', "", $arg[1]))); $x = str_replace("x", "", str_replace("=", "", str_replace('"', "", $arg[2]))); $x = $x * 20 - 13; $y = str_replace("y", "", str_replace("=", "", str_replace('"', "", $arg[3]))); $y = $y * 22 + 15; $a = str_replace("a", "", str_replace("=", "", str_replace('"', "", $arg[4]))); $a = radiansToDegrees($a); $t = str_replace("t", "", str_replace("=", "", str_replace('"', "", $arg[5]))); $e = str_replace("e", "", str_replace("=", "", str_replace('"', "", $arg[6]))); $f = str_replace("f", "", str_replace("=", "", str_replace('"', "", str_replace('/>', "", $arg[7])))); $blockimage = imagecreatefrompng("images/$n.png"); $blockimage = imagerotate($blockimage, -$a, 0, 0) ; imagealphablending($blockimage, false); imagesavealpha($blockimage, true); imagecopy($image, $blockimage, $x, $y, 0, 0, imagesx($blockimage), imagesy($blockimage)); //echo "$i | $n - $x - $y - $a - $t - $e - $f <br>"; } imagepng($image); imagedestroy($image); ?> if you require the .zip containing the images etc, just reply and i will upload it as soon as possible I have the following code, works rotates the image. But it seems to lose its transparency and add color when rotated to say 45. How can I avoid this? // File and rotation $filename = 'placeholder.png'; $degrees = 45; // Content type header('Content-type: image/png'); // Load $source = imagecreatefrompng($filename); // Rotate $rotate = imagerotate($source, $degrees, 0); // Output imagepng($rotate); ?> I have tried many solution, but nothing seems to fix this. The problem is that i put an image with transparency on top of another image, but the transparent pixels still transparent, where they should show some of the image below it. If you call it with l=100 and p=20 i would get this result http://cl.ly/566Z instead of this http://cl.ly/56OF. Here is the source code and I have attached the images: Code: [Select] <?php header('Content-type: image/png'); echo imagepng(progressbar($_GET['l'], $_GET['p'])); function progressbar($length, $percentage) { $length = round($length / 2) * 2; $percentage = min(100, max(0, $percentage)); if($length > 0) { $bar = imagecreate($length, 14); imagealphablending($bar, false); imagesavealpha($bar, true); $empty = imagecreatefrompng('Empty.png'); imagealphablending($empty, false); imagesavealpha($empty, true); $fill = imagecreatefrompng('Fill.png'); imagealphablending($fill, false); imagesavealpha($fill, true); $lempty = imagecreatefrompng('LeftEmpty.png'); imagealphablending($lempty, false); imagesavealpha($lempty, true); $lfill = imagecreatefrompng('LeftFill.png'); imagealphablending($lfill, false); imagesavealpha($lfill, true); $rempty = imagecreatefrompng('RightEmpty.png'); imagealphablending($rempty, false); imagesavealpha($rempty, true); $rfill = imagecreatefrompng('RightFill.png'); imagealphablending($rfill, false); imagesavealpha($rfill, true); $emptycaplength = min(7, $length / 2); //5 imagecopy($bar, $lempty, 0, 0, 0, 0, $emptycaplength, 14); imagecopy($bar, $rempty, $length - $emptycaplength, 0, 7 - $emptycaplength, 0, $emptycaplength, 14); if($length > 14) { imagecopyresized($bar, $empty, 7, 0, 0, 0, $length - 14, 14, 1, 14); } $filllength = round(($length * ($percentage / 100)) / 2) * 2; $fillcaplength = min(7, $filllength / 2); imagecopy($bar, $lfill, 0, 0, 0, 0, $fillcaplength, 14); imagecopy($bar, $rfill, $filllength - $fillcaplength, 0, 7 - $fillcaplength, 0, $fillcaplength, 14); if($filllength > 14) { imagecopyresized($bar, $fill, 7, 0, 0, 0, $filllength - 14, 14, 1, 14); } imagealphablending($bar, true); return $bar; } else { return false; } } ?> Guys thanks for helping me solve the problem i had but now i have another problem and i am lost. i have included the code below for you to have overview.
This is the code:
<table style="width:100%; margin-left:auto; margin-right:auto"> I am trying to understand PHP OOP and I have some code that is not working. here is the error code. Code: [Select] Parse error: parse error, expecting `T_FUNCTION' in C:\wamp\www\testing\armor_lib.php on line 11 And here is the armor_lib.php file: <?php class armor { // Head public $head; public $torso; public $pants; public $gloves; public $boots; // new stuff here class head extends armor { function __construct($head){ $this->set_head($head); } } // Torso class torso extends armor { function __construct($torso){ $this->set_torso($torso); } } // Pants class pants extends armor { function __construct($pants){ $this->set_pants($pants); } } // Gloves class gloves extends armor { function __construct($gloves){ $this->set_gloves($gloves); } } // Boots class boots extends armor { function __construct($boots){ $this->set_boots($boots); } } } ?> And here is the php in the armor.php file I have: <?php $head = new armor("Leather Helm"); $torso = new armor("Leather Shirt"); $pants = new armor("Leather Pants"); $gloves = new armor("Chain Mail Gloves"); $boots = new armor("Leather Boots"); echo "You are wearing: " . $head->get_head() . "on your Head"; echo "<br />"; echo "You are wearing: " . $torso->get_torso() . "on your Torso"; echo "<br />"; echo "You are wearing: " . $pants->get_pants() . "on your Legs"; echo "<br />"; echo "You are wearing: " . $gloves->get_gloves() . "on your Hands"; echo "<br />"; echo "You are wearing: " . $boots->get_boots() . "on your Feet"; ?> Any Help in understanding this will be much appreciated. Thanks. I'm trying to run a process using shell_exec, however the program i'm trying to run must communicate with a process that is not a system process, and everytime i run it, it fails, does anyone know how to make a apache/php server run active windows not in the system process? I do not receive email for my published php file which is: <?php ///// easend.php ///// $youremail = "acdelco40108@yahoo.com"; /*put the email address here, between quotes, the email address you want the message sent to*/ $to = $youremail; $email = $_POST['EMail']; $name2 = $_POST['Name']; $street2 = $_POST['Street']; $city2 = $_POST['City']; $state2 = $_POST['State']; $zip2 = $_POST['Zip']; $Phone = $_POST['Home_Phone']; $Cell = $_POST['Cell_Phone']; $education = $_POST['email1']; $comments = $_POST['email2'] ; $headers = "From:" . $email; $fields = array(); $fields{"Name"} = "Name"; $fields{"Street"} = "Street"; $fields{"City"} = "City"; $fields{"State"} = "State"; $fields{"Zip"} = "Zip"; $fields{"Home_Phone"} = "Home Phone"; $fields{"Cell_Phone"} = "Cell Phone"; $fields{"EMail"} = "Email"; $fields{"email1"} = "Education"; $fields{"email2"} = "Comments"; $subject = "We have received the following information from your employment application"; $body = "We have received the following information from your employment application:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: %s\n",$b,$_POST[$a]); } mail ($to, $subject, $body, $headers); //send mail to owner #end create email vars $headers = "From:" . $to; mail ($email, $subject, $body, $headers); //send mail to user #end create email vars echo "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"2; URL=ThankYou.html\"></head>"; ?> Hows it going guys. I am currently having a problem. I had a program that worked. I migrated the website and now the program is broken. Any time i try to run it, i get this error: Quote Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/thegoo20/public_html/class/wordgame/wordgame.php on line 31 Here is the code at that point: Code: [Select] function changeword(){ $result = mysql_query("Select words from CurrentWords"); $totalwords = array(); while ($row = mysql_fetch_array($result)){ $totalwords[] = $row["words"]; } $_SESSION['word'] = $totalwords[rand(0, count($totalwords)-1)]; $_SESSION['scrambled'] = str_shuffle($_SESSION['word']); } where line 31 is the while statement. Any help would be appreciated. Thanks Hi all. When I typed symbol ' in my textarea , after I submit it and view for what I typed , it will automatically add a slash in front of the ' . Such as the message is "I'm fine" , then it will turn out as "I\'m fine". Can I know what is the problem ? and how can I solve it? Thanks for every reply . so i want to call my php file with a query string to select a record out of a XML file... im close but cant get the variable i pass to be the record selected.. example... index.php?auction=1 i highlighted in red, where it doesnt pick up the proper row Code: [Select] <?php ini_set('display_errors', 1); error_reporting(E_ALL); $auction = $_GET{auction}; // parse the xml $xmlFileData = file_get_contents("items.xml"); $xmlData = new SimpleXMLElement($xmlFileData); [color=red]$location = $xmlData->item[$auction];[/color] //Retrieving the content from the selected item $title = $location->title; $value = $location->value; $itemnumber = $location->itemnumber; $description = $location->description; $donatedby = $location->donatedby; $image1 = $location->image1; $image2 = $location->image2; $image3 = $location->image3; $image4 = $location->image4; $image5 = $location->image5; $image6 = $location->image6; $image7 = $location->image7; $image8 = $location->image8; ?> <style> .itemimages img {width: 10px; height: 10px;} img.large {width: 100px; height: 100px;} </style> <script language="JavaScript" src="http://code.jquery.com/jquery-1.5.min.js" type="text/javascript"></script> <script> $().ready(function() { $(".itemimages img").click( $("#largepic").attr("src","this"); }); }); </script> <table border="1" cellpadding="10"> <tr> <td valign="top"> <img src="<?php echo $image1 ?>" alt="" border="0" class="large" id="largepic"><br> <div class="itemimages"> <?php // image 1 if (trim(''.$image1) != '') { echo "<img src='"; echo $image1; echo "' alt='' border='0'/> "; } // image 2 if (trim(''.$image2) != '') { echo "<img src='"; echo $image2; echo "' alt='' border='0'/> "; } // image 3 if (trim(''.$image3) != '') { echo "<img src='"; echo $image3; echo "' alt='' border='0'/> "; } // image 4 if (trim(''.$image4) != '') { echo "<img src='"; echo $image4; echo "' alt='' border='0'/> "; } // image 5 if (trim(''.$image5) != '') { echo "<img src='"; echo $image5; echo "' alt='' border='0'/> "; } // image 6 if (trim(''.$image6) != '') { echo "<img src='"; echo $image6; echo "' alt='' border='0'/> "; } // image 7 if (trim(''.$image7) != '') { echo "<img src='"; echo $image7; echo "' alt='' border='0'/> "; } // image 8 if (trim(''.$image8) != '') { echo "<img src='"; echo $image8; echo "' alt='' border='0'/> "; } ?> </div> </td> <td valign="top"> <?php echo $title ?><br> Estimated Value: <?php echo $value ?><br> Item Number: <?php echo $itemnumber ?><br><br> <?php echo $description ?><br><br> Donated by: <?php echo $donatedby ?><br> </td> </tr> </table> Hi everyone. I have written a PHP script gets data from a MySQL database and attempts to convert it to an RSS feed. The problem I am having is that when I preview the feed the "article_type", "article_author", "article_author2" and "article_company" information is not showing up in the feed. Have I coded this wrong? Thanks for any help. while($rss_array = mysql_fetch_array($rss_rs)) { $xml .= "<item><title><![CDATA[" . $rss_array['article_title'] . "]]></title> <link><![CDATA[index.php?skip=true&article=" . $rss_array['article_number'] . "]]></link><guid><![CDATA[index.php?skip=true&article=" . $rss_array['article_number'] . "]]></guid><description><![CDATA[" . str_replace("'", "", $rss_array['article_description']) . "]]></description> <article_type>" . $rss_array['article_type'] . "</article_type> <article_author>" . $rss_array['article_author'] . "</article_author> <article_author2>" . $rss_array['article_author2'] . "</article_author2> <article_company>" . $rss_array['article_company'] . "</article_company> </item>"; } |