Why won't my code work in Ubuntu Server 11.10? Is it because of gd library?

Posted by Derrick on Ask Ubuntu See other posts from Ask Ubuntu or by Derrick
Published on 2012-12-12T01:52:14Z Indexed on 2012/12/12 5:17 UTC
Read the original article Hit count: 277

Filed under:
|
|

I get this error when running the following code:

No such file found at "widgets/104-text.png"

I know that the code works because it works on my other non-ubuntu server. I do not know if it is gd library or what. I tried both the bundled version and the non-bundled and both do not make this code work.

$con = mysql_connect("localhost","user","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("satabase_name", $con);

$productid2 = $this->product->id;


$thename = mysql_query("SELECT * FROM pshop_product_lang WHERE id_product = '$productid2' LIMIT 1");


$thename2 = mysql_fetch_array($thename);


$string2 = $thename2['name'];


$string = (strlen($string2) > 25) ? substr($string2, 0, 25) . '...' : $string2;

$font  = 4;
$width  = imagefontwidth($font) * strlen($string);
$height = imagefontheight($font);

$image = imagecreatetruecolor ($width,$height);
$white = imagecolorallocate ($image,255,255,255);
$black = imagecolorallocate ($image,0,0,0);
imagefill($image,0,0,$white);

imagestring($image,$font,0,0,$string, $black);

imagepng($image, 'widgets/' . $productid2 . '-text.png');



$getimg110 = mysql_query("SELECT * FROM pshop_image WHERE id_product = '$productid2'");

$gotimg110 = mysql_fetch_array($getimg110);

$slash110 = addcslashes($gotimg110[id_image], '\0..\999999999999999999999');

$str110 = str_replace('\\', '/', $slash110); 

$newimg110 = '<img src="img/p' . $str110 . '/' . $gotimg110[id_image] . '-large_default.jpg" />';


include("conf.inc.php");

include('ImageWorkshop.php');


// Initialization of layer you need
$pinguLayer = new ImageWorkshop(array(
'imageFromPath' => 'widgets/background.png',
));



$pinguLayer2 = new ImageWorkshop(array(
'imageFromPath' => 'img/p' . $str110 . '/' . $gotimg110[id_image] . '-large_default.jpg',
));

$pinguLayer3 = new ImageWorkshop(array(
'imageFromPath' => 'widgets/' . $productid2 . '-text.png',
));

// resize pingu layer
$thumbWidth2 = 150; // px
$thumbHeight2 = 150;

$thumbWidth = 400; // px
$thumbHeight = 200;




$pinguLayer2->resizeInPixel($thumbWidth2, $thumbHeight2);
$pinguLayer->resizeInPixel($thumbWidth, $thumbHeight);

// Add 2 layers on pingu layer
$pinguLayer->addLayerOnTop($pinguLayer2, null, null, 'LM');
$pinguLayer->addLayerOnTop($pinguLayer3,  70, 25, 'MM');


// Saving the result in a folder
$pinguLayer->save("widgets/", $productid2 . ".gif", true, null, 95);

The file path is correct, however this part of the code is not creating the image as it is supposed to:

$thename2 = mysql_fetch_array($thename);


$string2 = $thename2['name'];


$string = (strlen($string2) > 25) ? substr($string2, 0, 25) . '...' : $string2;

$font  = 4;
$width  = imagefontwidth($font) * strlen($string);
$height = imagefontheight($font);

$image = imagecreatetruecolor ($width,$height);
$white = imagecolorallocate ($image,255,255,255);
$black = imagecolorallocate ($image,0,0,0);
imagefill($image,0,0,$white);

imagestring($image,$font,0,0,$string, $black);

imagepng($image, 'widgets/' . $productid2 . '-text.png');

© Ask Ubuntu or respective owner

Related posts about 11.10

Related posts about server