PHP - I Want To Make Transparent Background Here
session_start(); $text = rand(10000,99999); $_SESSION["vercode"] = $text; $height = 25; $width = 65; $image_p = imagecreate($width, $height); $black = imagecolorallocate($image_p, 255, 255, 255); $white = imagecolorallocate($image_p, 0, 0, 0); $font_size = 14; imagestring($image_p, $font_size, 5, 5, $text, $white); imagejpeg($image_p, null, 80);The code above creates an image with white background. How to change it to create transparent background? Similar TutorialsI have the following I use for uploading images, but I am having an issue with transparent background png images, they all get changed from transparent background to a black background. After doing some hunting around I see I neet to use imagealphablending and imagesavealpha to keep the trransparency, but it doesnt seem to be working I still get the black backgrounds, any ideas? Here is the script Code: [Select] <?php // Process new logo image if ($_FILES['logo']['tmp_name']&&$_FILES['logo']['tmp_name']!="") { // set memory limit for image ini_set("memory_limit","32M"); // Check file extension $checkfile=$_FILES['logo']['name']; $ext=substr($checkfile, -3); // Redirect if not correct image type if (!in_array($ext, array('jpg', 'JPG', 'gif', 'GIF', 'png', 'PNG'))) { header("Location: ../control_index.php?sponsors=error1"); // Close database connection mysql_close($link); exit (); } // Create logo image (300px wide) $file=$_FILES['logo']['tmp_name']; list($width, $height)=getimagesize($file); // Scale to width $main_width=300; $main_height=$height*($main_width/$width); if ($ext=="jpg"||$ext=="JPG") { $image=imagecreatefromjpeg($file); $newname="sponsor".time().".jpg"; } if ($ext=="gif"||$ext=="GIF") { $image=imagecreatefromgif($file); $newname="sponsor".time().".gif"; } if ($ext=="png"||$ext=="PNG") { $image=imagecreatefrompng($file); $newname="sponsor".time().".png"; } // Create main image file $main_image=imagecreatetruecolor($main_width, $main_height); imagecopyresampled($main_image, $image, 0, 0, 0, 0, $main_width, $main_height, $width, $height); $cp_file="../images/sponsors/".$newname; $site_file="../../images/sponsors/".$newname; if ($ext=="jpg"||$ext=="JPG") { imagejpeg($main_image, $cp_file, 100); imagejpeg($main_image, $site_file, 100); } if ($ext=="gif"||$ext=="GIF") { imagegif($main_image, $cp_file, 100); imagegif($main_image, $site_file, 100); } if ($ext=="png"||$ext=="PNG") { // Turn off alpha blending and set alpha flag imagealphablending($main_image, false); imagesavealpha($main_image, true); imagepng($main_image, $cp_file, 9); imagepng($main_image, $site_file, 9); } ?> So I'm new to PHP GD, I cant understand why the PNG image will not go transparent, it's just showing a white background.
Could anyone help me out with this?
Spoiler Hey all. I'm getting down the basics of the GD Library's image creation processes. I'm trying to test out creating png images. However, where there should be transparency there is a black background. Here's my code mostly based on the image tutorial found here at phpfreaks. Code: [Select] <?php // font $font = 'c:\windows\fonts\arial.ttf'; $fontsize = 12; // array of quotes $quotes = array( "I like pie.", "Surf's Up.", "Smoke em if you got em.", "Game on.", "I need TP for my bunghole."); // select quote $pos = rand(0,count($quotes)-1); $quote = $quotes[$pos]; // image $image = imagecreatefrompng('quote.png'); $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); imagettftext($image, 11, 0, 107, 32, $black, $font, $quote); imagettftext($image, 11, 0, 105, 30, $white, $font, $quote); // tell the browser that the content is an image header('Content-type: image/png'); // output image to the browser imagepng($image); // delete the image resource imagedestroy($image); ?> Cheers all, thanks! I am trying to copy an image into another image. Code: [Select] $im = imagecreatefrompng("/oldimg.png"); //this is a semi-transparent image where I want the new image to be copied imagealphablending($im, 1); //this seems to remove the black background header('Content-type: image/png'); //outputs old image with a transparent background (YAY!) imagepng($im); imagecopy($im, $newimage, 32, 0, 0, 0, 32, 32); //I want to replace a part of the old image with a new semi-transparent image header('Content-type: image/png'); //outputs image with a black background (noooooooooo!) imagepng($im); Can anyone help me? Hi all,
Any idea what Pinterest uses to make the background move please?
I searched everywhere and cannot find the answer:
https://www.pinterest.com/
I need the same type of background movement + popup on my site, it looks so nice!
Thank you,
Ben
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=317523.0 I am using the following code to give my image round corners, but i am using an image that just cuts the corner with a white shape. Is it possible to make it cut the corner with a transparent color? function roundcorners($image, $topleft, $topright = null, $bottomright = null, $bottomleft = null) { if($topright == null) $topright = $topleft; if($bottomright == null) $bottomright = $topleft; if($bottomleft == null) $bottomleft = $topleft; if($topleft >= 2) { $tl = imagecreatefrompng("corner.png"); imagecopyresampled($image, $tl, 0, 0, 0, 0, $topleft, $topleft, 485, 485); } if($topright >= 2) { $tr = imagerotate(imagecreatefrompng("corner.png"), 270, 0); imagecopyresampled($image, $tr, imagesx($image)-$topright, 0, 0, 0, $topright, $topright, 485, 485); } if($bottomright >= 2) { $br = imagerotate(imagecreatefrompng("corner.png"), 180, 0); imagecopyresampled($image, $br, imagesx($image)-$bottomright, imagesy($image)-$bottomright, 0, 0, $bottomright, $bottomright, 485, 485); } if($bottomleft >= 2) { $bl = imagerotate(imagecreatefrompng("corner.png"), 90, 0); imagecopyresampled($image, $bl, 0, imagesy($image)-$bottomleft, 0, 0, $bottomleft, $bottomleft, 485, 485); } } I'm wondering if the GD library is capable of coloring ONLY the non-transparent areas in an image. I had this image white, black, and every other color under the moon, but could only get GD to color the entire canvas (width and height) of the image with an opacity over it. I'm merging many layers on top of each other so I can't afford to color the entire square and lower the opacity and do some weird multiply stuff.
That's the image above. Then I have some lineart, markings, eye color, etc. So I had all my possible colors white areas that I layer on top of eachother. I want to color the entire non-transparent areas with a color (dynamic).. so I can't just color it in Photoshop and then upload it or else I would literally have millions of possibilities for every single color and shade..
Thanks for any help. I was trying to go with ImageMagick if GD isn't capable, but I can't even get that downloaded in my Wamp. I'm using 64 bit Wamp so I have no idea if that does something or whatever. I can get it installed on my computer and run it via command line, but I can't get it to work and render images in my Wamp files... can't ever find a .dll that works.
I’m trying to work out how I can use php gd to take an image, in this case it’s a rectangle that has text in the middle and the rest is transparent, so it’s a png with just text in the centre.
I have another image which is a texture. Its also a rectangle of the same size. I have managed to merge the two together so the texture on top of the text image but it covers the entire image rather than just the text in the middle.
what I need it to do it apply the texture to the text in the image and ignore the surrounding transparent pixels.
Okay so my news script is set to view only 10 pieces of news. But I want it so that it starts a new page once I have more than 10 pieces of news. Code: [Select] <?php require("functions.php"); include("dbconnect.php"); session_start(); head1(); body1(); new_temp(); sotw(); navbar(); $start = 0; $display = 10; $query = "SELECT * FROM news ORDER BY id DESC LIMIT $start, $display"; $result = mysql_query( $query ); if ($result) { while( $row = @mysql_fetch_array( $result, MYSQL_ASSOC ) ) { news_box( $row['news'], $row['title'], $row['user'], $row['date'], $row['id'] ); } mysql_free_result($result); } else { news_box( 'Could not retrieve news entries!', 'Error', 'Error', 'Error'); } footer(); mysql_close($link); ?> I tried a few things but they failed....miserably. Hi all, I am currently making a website that has e-custom functions and a back end for the client. I want them to be able to upload images - but they need to be transparent. I do not want to leave this in the hands of the client, so I am looking at ways of using the GD library to make the change I got no issue with the png/gif type for upload/resize function since this type already transparent background but my major problems is how to deal with jpeg/jpg image type which is their background was not a transparent...so is it possible I can change/ convert to png/gif type upon successful of uploading image...so the new final image will be png/gif type with transparent background...is it doable...I am not even sure it is possible...? Thanks for any help.. $looponce = 1; foreach ($this->info as $k => $v) { if ( (($k == 'subject') && ($v['required'])) && (!$this->settings['customSubject'])) { for ($i = 0; $i <= 0; $i++) { $output[] = $this->display_errors('error_system_subject'); } } if ( (($k == 'name') && (!$v['required'])) || ((!array_key_exists("name", $this->info)) && ($looponce == 1)) ) { $output[] = $this->display_errors('error_system_name'); $looponce++; } } That is my loop that i check things in. What i'm more interested in is the name if statement. If currently checks for a name key in an array(below) and makes sure that it is set to required. If it's not set to required, print out a system error and die()'s. I'm looking for ways to remove the need for program errors and just change them to what is needed to run. What i know how to do is, get into the inner array, what i don't know is how to edit the data and put it back exactly as it was given to me. The inner array data can be put back in any order, but the outer array must be in exact order as it was given. above code $this->info = $formdata; $formdata = array( 'name' => array('name'=>"Full Name", 'required'=>false, 'type'=>'text'), # This needs to be required=>true, but i can't trust the user, which is why i have the error. 'telephone' => array('name'=>"Telephone", 'required'=>false, 'type'=>'phone'), ); Any help is greatly appreciated, also am i doing the foreach loop in the code above in an efficient manner or is there another way? Hi there, As the question says i tried several things but i can't work it out and my knowledge about php isn't that well. Hi I just wanted to know how I can make this.... I want to write this in PHP, I dont know the best way to do this.... I am starting a software development company, Each time someone make a purchase of a software product I wan to include a cd key, I dont know how to include just one cd key... I want to place the cdkeys in a mysql db though which I know how to do, but just the fact of me taking only one cdkey out of it and it can't be used already... it has to go down the line how would I do this? Thanks ahead of time So I'm trying to make a counter that counts how many times a record on mysql database has been viewed. Not a hit counter for a webpage. In other words I have a page that displays the info of that record from the mysql database and within that page I would like to display the amount of times it has been viewed. Would anyone know where I can begin or send me to a good tutorial? Thanks Hi I had it on my old site but forgot what I put in the index.php file. Basicly, I want something like this: http://site.com/index.php?go=home or: http://site.com/index.php?home Does anyone know what I put in the index.php file to specify link and where it redirects too? Thank you. Basically, All I want to do is save a .txt (doesn't have to be .txt) to my FTP and PHP simple echos it. The .txt is where a message is stored. But when I write the message my self like this: Hello This is a message. - And then upload it to my FTP, PHP echos it like this "HelloThis is a message". Is there anyway for PHP to notice the 'white space'? --OR-- If you know of a better way to make a message system, then also let me know Thanks, Ollie! I have some code which i think is really inefficient especially as there will be more more conditions to be met. I was thinking about using s switch but don't know if this is possible or if it's best leaving as it is. Any ideas? if($parts[($i-1)]=="forum") { //do some code } else if($parts[($i-2)]=="forum") { //do code } else if (($parts[($i-1)]=="list-messages") && (isset($parts[($i+1)]))) { //do code } else { // do some code } I used this code $limit = 120; if (strlen($summary) > $limit) $summary = substr($summary, 0, strrpos(substr($summary, 0, $limit), ' . . .')); This code ok in English Language it counts letters fine but it is not work fine if I insert Arabic text. It counts Arabic encoding characters. I am using this line of code my site Code: [Select] <?php echo (IMAGES_HEADER . "header_02.jpg" ?> I have a page defining all my directories, on that page I have this Code: [Select] define('IMAGES_HEADER', DIR_IMAGES . 'header/'); instead of showing the image, all I am getting is "IMAGES_HEADERheader_02.jpg" where the image should be. I am very new to PHP and trying to learn it, what in the world am I doing wrong?? Rab |