Hello Does anybody know why this code is only working locally on xampp but not on remote server where I just see a black rectangle instead of the word "phone"? You can check it at http://www.arreglaordenador.com/numberimage4.php <?php $fontDir = $rootPath . "fonts\\"; header("Content-type: image/png"); //Picture Format header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // NO CACHE /*image generation code*/ //create Image of size 350px x 75px $bg = imagecreatetruecolor(350, 75); //This will make it transparent imagesavealpha($bg, true); $trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127); imagefill($bg, 0, 0, $trans_colour); //Text to be written $helloworld = isset($_GET['text']) ? $_GET['text'] : "phone"; // White text $white = imagecolorallocate($bg, 255, 255, 255); // Grey Text $grey = imagecolorallocate($bg, 128, 128, 128); // Black Text $black = imagecolorallocate($bg, 0,0,0); $font = 'arial.ttf'; //path to font you want to use $fontsize = 20; //size of font //Writes text to the image using fonts using FreeType 2 imagettftext($bg, $fontsize, 0, 20, 20, $grey, $fontDir.$font, $helloworld); //Create image imagepng($bg); //destroy image ImageDestroy($bg); ?> Code (markup): Thank you very much.
put this at the top error_reporting(E_ALL); ini_set("display_errors", 1); it will output errors if any
I do not know why the transparency of this code works fine locally but not in the remote server. Well, the transparency works fine in the local server as long as you do not use internet explorer but firefox or other browser. Well I think the reason is that the sentence imagesavealpha($bg, true); Code (markup): might not be working in the remote server but I do not know why. The whole code is this: <?php $fontDir = "fonts/"; /*image generation code*/ //create Image of size 350px x 75px $bg = imagecreatetruecolor(350, 75); //This will make it transparent imagesavealpha($bg, true); $trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127); imagefill($bg, 0, 0, $trans_colour); //Text to be written $helloworld = isset($_GET['text']) ? $_GET['text'] : "phone"; $red = imagecolorallocate($bg, 255, 0, 0); $font = 'arial.ttf'; //path to font you want to use $fontsize = 20; //size of font //Writes text to the image using fonts using FreeType 2 imagettftext($bg, $fontsize, 0, 20, 20, $red, $fontDir.$font, $helloworld); header("Content-type: image/png"); //Picture Format //Create image imagepng($bg); //destroy image ImageDestroy($bg); ?> Code (markup): Nonetheless, now I have an alternative and different code which does successfully what I wanted not only locally but also in the remote server and seems to work with all the browsers even with internet explorer. The code comes here: <?php // Create a 55x30 image $im = imagecreate(105, 20); $transp = imagecolorallocatealpha($im, 0, 0, 0, 127); $textColor = imagecolorallocate($im, 0, 0, 0); imagestring($im, 4, 0, 2,"phone", $textColor);// Save the image header("Content-type: image/png"); imagepng($im); imagedestroy($im); ?> Code (markup): Cheers!
It´s most likely because the libary extension is setup different, have a look in your php info and see if that particular function has been enabled. Glen
Hello Question, how do I know if I have that particular function enabled just by looking at the phpinfo() information. I just took a glance at it and it said this: Configure Command './configure' '--prefix=/usr/local/php5' '--with-mysql=/usr' '--with-gd' '--with-gzip' '--with-zlib' '--with-kerberos' '--enable-ftp' '--enable-gd-native-ttf' '--with-freetype-dir=/usr' '--with-jpeg-dir=/usr' '--with-xpm-dir=/usr' '--with-png-dir=/usr' '--with-imagick' '--enable-bcmath' '--with-xml' '--with-dom' '--with-gettext' '--enable-mbstring' '--with-curl' '--with-imap' '--enable-calendar' '--enable-mhash' '--enable-openssl' '--with-openssl=/usr' '--enable-exif' '--with-mhash=/usr' '--enable-mcrypt' '--with-mcrypt=/usr' '--with-imap-ssl' '--enable-xslt' '--with-dom-xslt=/usr' '--with-xslt-sablot=/usr' '--with-config-file-path=/home/sys/php5' '--with-pgsql=/usr' '--with-pdo-mysql' '--with-pdo-pgqsl' '--with-mysqli' '--with-pear' '--with-iconv' '--with-xsl=/usr' '--enable-fastcgi' GD Support enabled GD Version bundled (2.0.34 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.1.7 GIF Read Support enabled GIF Create Support enabled JPG Support enabled PNG Support enabled WBMP Support enabled XPM Support enabled XBM Support enabled Is there any problem with that? Should I look at other part of the info from the phpinfo()? Thanks
Well, I do not know if this has something to do, but it might have to do. You can check this: http://www.justskins.com/forums/406...osite-effect-on-transparent-color-136764.html Regards.
Have a look at this, php.net/manual/en/function.function-exists.php Check if the function is actually enabled on your system. Glen
It seems it is actually enabled. Actually you can check it. I wrote this <?php if (function_exists('imagesavealpha')) { echo "IMAP functions are available.<br />\n"; } else { echo "IMAP functions are not available.<br />\n"; } ?> Code (markup): in http://www.arreglaordenador.com/functionexists.php and it returns IMAP functions are available.
the issue in IE may be due to IE6 not supporting png images.. also for imagettf you need to have the fonts in the right place on the server too.. do you have the font in place ?
With the first code I placed, yes the problem might be around not getting access to the fonts. But witth the second, that was not the problem. I do not know why because I did not change anything but the code <?php $fontDir = "fonts/"; /*image generation code*/ //create Image of size 350px x 75px $bg = imagecreatetruecolor(350, 75); //This will make it transparent imagesavealpha($bg, true); $trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127); imagefill($bg, 0, 0, $trans_colour); //Text to be written $helloworld = isset($_GET['text']) ? $_GET['text'] : "phone"; $red = imagecolorallocate($bg, 255, 0, 0); $font = 'arial.ttf'; //path to font you want to use $fontsize = 20; //size of font //Writes text to the image using fonts using FreeType 2 imagettftext($bg, $fontsize, 0, 20, 20, $red, $fontDir.$font, $helloworld); header("Content-type: image/png"); //Picture Format //Create image imagepng($bg); //destroy image ImageDestroy($bg); ?> Code (markup): seems to be working now in the remote server www.arreglaordenador.com/numberimage4.php I mean, it is not showing a black rectangle anymore because transparency is working. To your answer, the font is there. Anyways, I think the problem was that for some reason transparency was not working well in the server, that is to say, the function imagesavealpha($bg, true); was not doing what was supposed to do. Otherwise I would not have seen a black rectangle when I run the code in the server. Actually, when I run the code in local server then I did not see that black rectangle because this sentence imagesavealpha($bg, true); made it transparent. But now it seems it is also working in the remote server. Thanks though.