SilverJester Posted May 5, 2011 Share Posted May 5, 2011 I'm trying to write a script that will copy images from one website (a supplier, in this case puma) and save them to the dealer's web server. I have already done this for other supplier's websites but puma uses png's instead of jpeg's and I believe that is what is causing my issues: The original image looks like this: The copied image some odd colors in the background like this: Here is the code: $puma_image = "http://www.pumab2b.com/_static/images/styleColors/1234560002/" . str_replace(" ", "", $Item_Num) . "_1.png"; $image = imagecreatefrompng($puma_image); if ($image) { //Save image to Soccer Etc server (images folder): if (imagepng($image, "prod_images/" . $cur_Item['Item_Num'] . ".png", 0)) { //DO some other stuff here } } I just noticed after posting the original image on this forum, that it is actually transparent. I'm guessing this has something to do with my problems? Quote Link to comment https://forums.phpfreaks.com/topic/235643-problem-with-gd-library-and-pngs/ Share on other sites More sharing options...
spiderwell Posted May 5, 2011 Share Posted May 5, 2011 i dont know much about it either but you probably have to specify transparancy, and in my limited knowledge of that in images, i expect you need to set background to black as that appears to be the transparency color for the original image, hence the white/black thing. i guess from that the png you create has a default background of white. so if im right you need to set background to black then set black as transparent. makes sense in my tiny mind anyways, sorry not much use of a post really Quote Link to comment https://forums.phpfreaks.com/topic/235643-problem-with-gd-library-and-pngs/#findComment-1211139 Share on other sites More sharing options...
SilverJester Posted May 5, 2011 Author Share Posted May 5, 2011 ah ok I found a solution: imagealphablending($image, false); imagesavealpha($image, true); I added those two lines before saving the file. But I'm honestly not sure what they are doing, maybe someone would be willing to explain it? Quote Link to comment https://forums.phpfreaks.com/topic/235643-problem-with-gd-library-and-pngs/#findComment-1211142 Share on other sites More sharing options...
spiderwell Posted May 5, 2011 Share Posted May 5, 2011 an understands of how it works always helps, but the fact it is working now is the important part Quote Link to comment https://forums.phpfreaks.com/topic/235643-problem-with-gd-library-and-pngs/#findComment-1211146 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.