Jump to content

PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given


shams

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
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.