Remove A Black Background From An Image To Make It Transparent Using GD
is it possible to remove a black background from an image to make it transparent using GD. for example. can i pass the radius of the moon to GD (as it is on the image) and have it slice the moon out so to speak leaving it on a transparent background.
View Complete Forum Thread with Replies
Related Forum Messages:
PHP (GD) Created Transparent PNG: AlphaImageLoader Makes Black Parts Transparent Instead Of Transparent Color Set With PHP
I have a problem with PHP (GD) created transparent PNG and Microsofts AlphaImageLoader. You will immediately see what the problem is if you view http://www.useful-scripts.biz/test/.../transpng_2.php with IE 7 or Firefox and then with IE 6. It seems that the AlphaImageLoader works correctly on a PNG image that has been created with an image processor and then uploaded, but not with a PNG image created with PHP. It seems to ignore the transparent color set with PHP and instead to render the black color transparent. The image in question was created using this code: <?php $source = imagecreatefrompng("parrot_orig.png"); $transp = imagecolorallocate($source,255,0,0); imagecolortransparent($source,$transp); imagefilledrectangle($source,15,15,70,70,$transp); imagepng($source,"parrot_php.png"); ?> The HTML used on the page is this:
View Replies !
Transparent Background
i'll try to explain myself the best i can, here is the problem: i have a html page and inside this i want to put an iframe that contains a php page. That's ok, i can do it and it works, but the problem is that i can't make that php document to have transparent background. it turns white. Is it because of the iframe? the php document has transparent background, but when i see it inside the iframe it doesn't work.
View Replies !
GD Imagecopy Problems With Black Background
This function is part of a class, it basically creates a new image in the dimensions specified, and then copies in the image held in $this->image. The image that is copied in will never be bigger than the new image (that is taken care of in another function) but one or both of the dimensions could be less than the new image (if the ratio isn’t the same). It all works perfectly, it creates a new true colour image, fills it in white, but then when it runs the imagecopy function it seems to forget the fact that I set the background to white, and the image that results has a black border. For example if I wanted a 100x100 image, and I was copying a 100x50 image in, I would end up with a 100x100 image with the old image centred vertically and a 25px black stripe above and below, I want those stripes to be white. Any ideas? function crop($width = null, $height = null) { // get the current widths and heights $current_width= imagesx($this->image); $current_height= imagesy($this->image); $crop_top = floor(($current_width - $width) / 2); $crop_left = floor(($current_height - $height) / 2); // create a new image resource $temp= imagecreatetruecolor($width, $height); $white= imagecolorallocate($temp, 255, 255, 255); imagefill($temp, 0, 0, $white); // copy image into new resource imagecopy($temp, $this->image, 0, 0, $crop_top, $crop_left, $width, $height); // destroy original image imagedestroy($this->image); // copy new image $this->image = $temp; }
View Replies !
Black Background On Rotated Images....
I need to rotate an image 5 degrees in PHP for a site I'm working on. The image rotates fine using the imagerotate() function, the problem is the background where it was before turns to black. Any ideas how to fix this?
View Replies !
Imagerotate(), Producing A Black Background Color
I am having this Image, the background of the image is transparent But on rotation using imagerotate(), it is producing a black background color. This background color is coming on using any function on the original image ie, like imagecopy() etc . I have used imagecolortransparent() to suppress the color, but still the problem is coming.
View Replies !
ImageCopyResampled - How To Avoid Default Black Background?
I would like to know how to avoid the default black background color in ImageCopyResampled if origin and destination do not fit. ImageCopyResampled puts always a black background and if I try to fill it with another color and with ImageFill function, ... I get problems: Some images with a deep dark colors predominance or even with a deep light color predominance too, are filled with my color, as you know, applied with ImageFill. Code:
View Replies !
Make Thumbnail Transparent
I have a script that will upload an image, then create a thumbnail of that image. When I upload an image with a transparent background the normal sized image comes out with a transparent background, but the thumbnail image comes out with a black background. Code:
View Replies !
Make A Colour Transparent
I would like to do is grab an image, determine what colour is at a certain pixel (maybe 10, 10) and then set that colour to transparent for the whole image. Basically it is so that I can dynamically place an image on various backgrounds for previewing. I am not worried about perfection (anit-aliasing, matte, etc).
View Replies !
Creating Image From Uploaded Image And Transparent PNG
Say the client wants to be able to change the image, but not the text treatment, and doesn't have the Photoshop knowledge to actually replace it and re-save it themself. Is there anyway to use a PNG with the rounded edges, text treatment, and transparent center, have the client upload a standard rectangular-shaped image, and use PHP to layer the uploaded image underneath the transparent one, creating a new image file?
View Replies !
Transparent Image
Hi! Here's a piece of code: [begin] <?php Header('Content-type: image/png'); $sz = ""; $FileValue = 1000; $i = strlen($FileValue); for ( $j = 0; $j < 7-$i; $j++ ) { $sz = $sz . "0"; } $Img = imagecreate(56,13); $Gold = imagecolorallocate($Img,148,128,100); $Gray = imagecolorallocate($Img,32,32,32); ImageFilledRectangle($Img,0,0,55,12,$Gray); imagestring($Img,4,0,0,$sz.$FileValue,$Gold); imagepng($Img); ImageDestroy($Img); ?> [end] OK. Calling this script I have a png picture back. Now I add imagecolortransparent($Img,$Gray); just before imagepng() and OK again, I have a transparent picture back. But now, if I add: $r = imagerotate($Img,90,0); imagepng($r); just after the imagecolortransparent() instruction seen above, I get a rotated picture, but not transparent. How to solve that? I've used a plenty of tricks, no one works.
View Replies !
Uploaded Image Has Black Bar
I was wondering if anyone has ever encountered a problem with an uploaded and resized image that now has a black bar on the right side of the image? The image is uploaded and resized properly via a form, however the right 10% of the image is black.
View Replies !
Transparent Text On Image?
Is it possible to place transparent text on an image? I want to display an image of some text in a fancy typeface, but superimpose text in a plain style, so that it can be copied and pasted; a bit like what you see in some PDF files, where the page image is visiable, the overlying text is not.
View Replies !
Imagecreate Output A Solid Black Image
I'm making thumbnails. I want to first scale down the image before I crop it even smaller. The code below only creates a solid black square. Actually, only $final_im creates an image that's solid black. If I used $im as the output file (if I use this instead: imagejpeg($im, "$new_name") ), it's fine (albeit a very low quality image that does not have the dimensions I desire). I figure the problem lies at the //create final thumbnail section of the code. But, again, everything looks right. I would try other functions like imagecopyresizedbicubic , or imagecopyresampled but my server is using an older GD version, and I cannot upgrade it (ISP's server). PHP Code:
View Replies !
Error In Converting GIF Image To Black & White
I have a doubt in php.I wrote a php program to convert colour Images to balck & white.It is working fine with JPEG files and PNG files.When it comes to GIF files I am not getting the colour Image.I think I found the reason of getting error.But I am not able to solve it I am pasting the code which I wrote The reason I think is when I am extracting the RGB value from the image,R and G will be zero everytime.But I am getting the value of B. As a Result I am getting a Black Box instead of Black and white Image $file = 'logo2.gif' header('Content-type: image/gif'); $imgtype = "gif"; list($width, $height) = getimagesize($file); $source = imagecreatefromgif($file); $bwimage= imagecreate($width, $height); for ($c=0;$c<256;$c++) { $palette[$c] = imagecolorallocate($bwimage,$c,$c,$c); } function yiq($r,$g,$b) { return (($r*0.299)+($g*0.587)+($b*0.114)); } for ($y=0;$y<$height;$y++) { for ($x=0;$x<$width;$x++) { $rgb = imagecolorat($source,$x,$y); $r = ($rgb >16) & 0xFF;//error is here I am getting a value of zero for $r and $g $g = ($rgb >8) & 0xFF;//error getting the value zero everytime $b = $rgb & 0xFF;//Here I am getting value $gs = yiq($r,$g,$b); imagesetpixel($bwimage,$x,$y,$palette[$gs]); } } imagegif($bwimage);
View Replies !
Createimagefromjpeg With URL's Produces Black Image
i only see a black image when i use createimagefromjpeg with URL. i even used a native url and it is still the same. when i use direct path, i can see the image though. what could the possible cause be? this is run on linux server and allow_url_fopen is turned on.
View Replies !
Problem W/ Imagecreate() To Pdf ->image Printing Black Fuzz
this may be an issue with printer or something but i was wondering if anyone had seen this before?? info.... -the application is a work order request form that generates a pdf of form w/ user's input filled in. -a unique "request number" is created and is put in the pdf via imagecreate() - black text on a white background. for some people, the image/request number displays fine but when printed, is a black fuzzy block (see image below) taken from scan of printed form: http://www.alumni.uga.edu/it/beta/request_num_pdf.gif
View Replies !
Background Image
i created a calendar in php. i have this calendar displayed on another php page (index.php). i added a background image to the calendar. it displays fine on the calendar alone but it won't display as a background image when i display it on index.php.
View Replies !
Background Text Image
How can I place text on a page like a watermark background. For example, I may want to put FOR SALE in large red letters in the center of a page at a 10% opacity then write text over it from the initial point of origin. I've tried using style commands, but the results are inconsistant.
View Replies !
Random Background Image
I'm designing a site that needs to do the following: Select randomly from a series of about 5 different background images Store the selected image name in a session variable I'm pretty sure that I can setup it's selecting randomly from images and storing it in a session variable. The thing I can't figure out is how I should execute it most efficiently. Will it work to do a php file include of the php file that has the code.
View Replies !
Random Background Image + CSS
I have images stored in a server folder with metadata in Database. The images are to be used as Background Images set in a .CSS file... background: #fff url('../images/main_bg.jpg'); How do I display images by random in the CSS file? Is it possible?
View Replies !
Text On A Background Image
it needs to have the background of another image (bg.jpg) and then have text printed on top of it. I have tried jpgraph but it was to hard to understand then i tried this:   <?php         header ("Content-type: image/png");         $img_handle = ImageCreate (230, 20) or die ("Cannot Create image");         $back_color = ImageColorAllocate ($img_handle, 0, 10, 10);         $txt_color = ImageColorAllocate ($img_handle, 233, 114, 191);         ImageString ($img_handle, 31, 5, 5,  "My first Program with GD", $txt_color);         ImagePng ($img_handle);  ?>
View Replies !
Background Image Load Problem
I have a table with a large background image: <table style='background-image: url(images/eagle_country_large.jpg); ..'> The problem is that everything on the page loads except there is a big delay with the loading of the image. It's not like a regular image loading. Somehow it looks like the page is finished, then a delay, and then the background picture appears. It's even worse on a dialup connection. Code:
View Replies !
Question About Adding A Background Image
I have searched and dug and I have looked at probly every thread on hear and I have still not been able to figure out how to put up a simple background image I have tried a couple things from different threads but when I enter in the code I either get light blue background, no page at all, or the same as what I started with. Here is what I am adding (with many variations) <body style="background: #CCFFFF url('../../images/adrian18.jpg');">' It works fine in my editor (dreamweaverMX) but when I upload it I get nothing. Please treat me like I am Stupid, the reason is because I don't know for sure If I have been editing the right file. the file I have been editing is index.tpl under my /templates/ folder, because it sets my layout, I do also have a index.php in my root folder.
View Replies !
Image Create Default Background Color
I have a script that crops and image and resizes it, but that's not the problem. If the image is smaller than the crop area, PHP just fills it in with black. Is there a way to make PHP fill it in with white instead of black?
View Replies !
Remove Extra Characters From A Title That The User Types In To Make It More URL-friendly.
I am trying to remove extra characters from a title that the user types in to make it more URL-friendly. I am trying to use preg_replace() for it, but I keep getting errors. Here's my code: Code: $urlFriendlyTitle = preg_replace("/[/", "", $_POST['title']); $urlFriendlyTitle .= preg_replace("/]/", "", $urlFriendlyTitle); $urlFriendlyTitle .= preg_replace('/ /', '_', $urlFriendlyTitle); When I remove the space it's fine, but trying to remove brackets just doesn't work. I haven't tried to remove Quotaion Marks or Slashes/ other characters yet(ex @, #, $, &, etc..), but hopefully I can figure that out once I fix the bracket problem.
View Replies !
Preg_match Img Src Then Remove Entire Image Tag From Html
I have a table with rows of small bits of html code. I have already set it up to look for each row that has an image in the code like so <img src="http://www.site.com/file.jpg" width="80" height="90"> I need to create a program with preg_match and preg_replace that will first find the image file's source and then remove the entire image tag. the image tags can be slightly different. some have the '/' at the end and some come with alt tags. How can I do this? I need to get the source then remove the whole thing entirely.
View Replies !
Make A Duplicate Row Of Saving The Image
I have image in database tables. I want to make a duplicate row of aving the image. how can i do it ? query like: insert into table_name (image_column) values (select image_column from table_name); Above query is not working.
View Replies !
Make A Greyscale Image Out Of Array, Scaled To The Maximum Pixel?
Can the GD library do this? I have an array of numbers (which I shall be manipulating server-side), which I wish to convert into an image. The elements of the array are essentially the 1D subscripts of a 256*256 image. I've been looking at the GD library functions all day, but I can't seem to translate the array to a jpeg or png or whatever. (The GD library functions are working though.) It seems that creating an image from another image is easy, but not from the raw data. How can I make a greyscale image out of this array, scaled to the maximum pixel?
View Replies !
Transparent GIF
I am trying to resize transparent GIF images, so I was reading, and they say to use fopen, fread, and read the first 13 bytes... OK, so I read in a transparent gif, and the first 13 bytes... and echo it out to the screen, and I get this: GIF89a›�s�÷��What am I supposed to do with that? they then say "allocate that color as transparent, and use imagecopy(); to set the transparency back."
View Replies !
Transparent .png
This isn't totally related to php, but I am using a php generated page that is using transparent .png's. Anyway, when I view the page in Internet Explorer, the transparency within the png is replaced with grey?? But when I view it in Firefox it works fine?
View Replies !
My Thumbnails Are Black
The code below is mean to create thumbs for all images in a folder however they just come out black. Is there an arror or is it a gd function that isnt supported with gd 2.0.28 Code:
View Replies !
Black Border
I'm trying to draw a black border around all my pictures. I get a border as the result but. The borders are all kinds of colors, different grays, white and black. It seems like random. I want black and only black. PHP Code: // Create border around image $black = imagecolorallocate($image,0,0,0); imageline($newimg, 0, 0, 0, $new_height, $black); imageline($newimg, 0, 0, $new_width, 0, $black); imageline($newimg, $new_width-1, 0, $new_width-1, $new_height-1, $black); imageline($newimg, 0, $new_height-1, $new_width-1, $new_height-1, $black);
View Replies !
|