ivoilic Posted March 1, 2012 Share Posted March 1, 2012 So 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 here: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: <?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? Quote Link to comment https://forums.phpfreaks.com/topic/258020-transparency-help/ Share on other sites More sharing options...
jcbones Posted March 1, 2012 Share Posted March 1, 2012 Warning: imagepng() [function.imagepng]: Unable to open './imagecolortransparent.png' for writing: Permission denied in /Library/WebServer/Documents/temp/test.php on line 21 The bolded text tells us that the permissions on that file are not set to allow the server to write to it. You will have to change the permissions on the file to allow it to work. I would start with 644. Quote Link to comment https://forums.phpfreaks.com/topic/258020-transparency-help/#findComment-1322591 Share on other sites More sharing options...
ivoilic Posted March 2, 2012 Author Share Posted March 2, 2012 Can you please explain in more detail, I'm a bit of a noob... Quote Link to comment https://forums.phpfreaks.com/topic/258020-transparency-help/#findComment-1322933 Share on other sites More sharing options...
jcbones Posted March 2, 2012 Share Posted March 2, 2012 Well, file permissions are an important part of servers, as they restrict who can do what with a file (as you have just found out). Being that I am inherently lazy, I'm going to ask that you look here, and if you encounter more questions or get massively confused (it happens), I'll see if I could help. My communications skills have been lacking lately, and I would probably confuse you more than those links, ATM. Quote Link to comment https://forums.phpfreaks.com/topic/258020-transparency-help/#findComment-1322938 Share on other sites More sharing options...
ivoilic Posted March 2, 2012 Author Share Posted March 2, 2012 Thank you for the link, I now understand what you meant by 644. However I still don't know how to change the permissions since I am using apache server to test out my files locally. Quote Link to comment https://forums.phpfreaks.com/topic/258020-transparency-help/#findComment-1322944 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.