Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/258020-transparency-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/258020-transparency-help/#findComment-1322591
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/258020-transparency-help/#findComment-1322938
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.