shams Posted July 27, 2017 Share Posted July 27, 2017 Hi, In the ubuntu when i run the code get the error: [Thu Jul 27 13:45:13.545084 2017] [:error] [pid 12255] [client 192.168.1.100:36622] PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /var/www/me.usa.cc/index.php on line 40 This is the code: <?php // Set the content-type header("Content-type: image/png"); // Create the image $im = @imagecreatefromgif('GD/bg.gif'); // Create some colors $black = imagecolorallocate($im, 0, 0, 0); $blue = imagecolorallocate($im, 0, 0, 255); // Replace by your own font // full path and name $local = $_SERVER['SCRIPT_FILENAME']; $pos = strrpos($script, '/'); $path = substr($script, 0, $pos); $font = '/home/user/.fonts/truetype/BahijNazanin/BahijRegular.ttf'; // UTF-8 charset $text = 'ﺐﺴﻣ ﺎﻠﻠﻫ ﺎﻟﺮﺤﻤﻧ ﺎﻟﺮﺤﻴﻣ'; imagettftext($im, 20, 0, 10, 50, $blue, $font, 'UTF-8:'); imagettftext($im, 20, 0, 200, 50, $black, $font, $text); require('I18N/Arabic.php'); $Arabic = new I18N_Arabic('Glyphs'); $text = 'ﺐﺴﻣ ﺎﻠﻠﻫ ﺎﻟﺮﺤﻤﻧ ﺎﻟﺮﺤﻴﻣ'; $text = $Arabic->utf8Glyphs($text); imagettftext($im, 20, 0, 10, 100, $blue, $font, 'ArGlyphs:'); imagettftext($im, 20, 0, 200, 100, $black, $font, $text); // Using imagepng() results in clearer // text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> Line 40 is the last line. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted July 27, 2017 Share Posted July 27, 2017 This is just the last message in a whole block of errors, right? Well, yes, your code has problems. Not only do you have zero error checking. You actively suppress the error messages which could actually tell us what's going on. In other words, you've made it pretty much impossible to debug your problem. You need to fix that. Do not suppress errors (unless you absolutely know what you're doing). The "@" operator is evil. Secondly, do not assume that code will never fail. You've just been proven wrong. Everything fail. When you try to read a GIF file, that file may not exist, or it may not have the right permissions, or it may be invalid. You have to be prepared for that, thoroughly check every single return value and log every possible error. Quote Link to comment Share on other sites More sharing options...
shams Posted July 27, 2017 Author Share Posted July 27, 2017 Thanks for reply, the problem solved, when i run the index.php from the right folder. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted July 27, 2017 Share Posted July 27, 2017 You haven't solved anything. Quote Link to comment 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.