Why my image created by php is not displaying?

367

I have a problem , I have a software that gets pc tech specs and post them online and we are offering a signature image for each specs, this is created by php , but is not working anymore; Demo link : http://checkmyspecs.co.uk/button.php?id=646725 or go to any specs page , example : http://www.checkmyspecs.co.uk/display2.php?id=646725 and down on the page is grab button code.

The image must be created by button.php , here is the code :

<?php

include "db.php"; 

function getdata($viewerid) { 
$query = "SELECT * FROM data where viewerid = '$viewerid'"; 

$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
$data = array(); 
array_push($data,$row['bootmethod'],$row['ComputerCaption'],$row['Infrared'],$row['DayLight'],$row['ManufacturerBox'],$row['Model'],$row['cores'],$row['memory'],$row['monitor'],$row['resolution'],$row['pixels'],$row['cpuvoltage'],$row['clockspeed'],$row['AddressWidth'],$row['SocketDesignation'],$row['cpuname'],$row['loadpercent'],$row['applications'],$row['videocardname'],$row['refreshrate'],$row['videodriver'],$row['installed'],$row['hddata'],$row['directx']); 
return $data; 
} 


function LoadPNG($imgname,$cur)
{

$getvalues = getdata($cur);

/* Attempt to open */
$im = @imagecreatefrompng($imgname);
// Removes white background (made from the original transparency)
$white = imagecolorallocate($im, 255, 255, 255);
// Make the background transparent

//Generate the text to write onto the image (the php Version).
//Don't know much about this


// Add some shadow to the text

$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
$blue = imagecolorallocate($im, 0, 173, 238);
$darkblue = imagecolorallocate($im, 54, 154, 191);



$font = '/fonts/arialbd.ttf';

$ramo = $getvalues[7];
$cpuo = $getvalues[15];
$gpuo = $getvalues[18];
$screeno = $getvalues[9];

$ram = "$ramo MB"; 
$cpu = "$cpuo"; 
$gpu = "$gpuo "; 
$screen = "$screeno"; 

imagettftext($im, 11, 0, 40, 23, $black, $font, $cpu);
imagettftext($im, 11, 0, 40, 53, $black, $font, $gpu);
imagettftext($im, 11, 0, 40, 83, $black, $font, $screen);
imagettftext($im, 11, 0, 40, 113, $black, $font, $ram);


// write text
$textcolor = imagecolorallocate($im, 0, 3, 0);
return $im;
}
header('Content-Type: image/png');
$button = '/images/button.png'; 
$img = LoadPNG($button,$_GET['id']);
imagepng($img); 


?> 
683

Answer

Solution:

Your image isn't an image. Here's what is really being output:


Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 24

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 33

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 34

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 35

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 36

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/checkmys/public_html/button.php on line 37

Fatal error: Call to undefined function imagettftext() in /home/checkmys/public_html/button.php on line 53

You can use tools such as Fiddler to see this, even when your content-type is set as an image. If you would remove that@ symbol, we could see the error describing why your image could not be created.

Also, you are currently wide open to SQL injection. You should use prepared queries with PDO to avoid this problem.

People are also looking for solutions to the problem: php - Watch directory for new files with javascript

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.