PHP运行错误
<?php//checkwehavethevariabledata//variablearebutton-textandcolor$button_text=$_REQUE...
<?php
//check we have the variable data
//variable are button-text and color
$button_text=$_REQUEST['button_text'];
$color=$_REQUEST['color'];
if((empty($button_text)||empty($color))||(!($color=='red'||$color=='blue'||$color=='green')))
{
echo 'Could not create image - from not filled out correctly.';
exit;
}
//create an image of the right background and check size
$im=imagecreatefrompng($color.'-button.png');
if(!$im)
{
echo 'Could not create image.';
exit;
}
$width_image=imagesx($im);
$height_image=imagesx($im);
//out images need an 18 pixel margin in from the edge of the image
$width_image_wo_margins=$width_image-(2*18);
$height_image_wo_margins=$height_image-(2*18);
//work out if the font size will fit and makeit saller untili it does
//start out with the biggest size that will reasonably fit on ourt butons
$font_size=33;
//you need to tell GD2 where your fonts reside
putenv('GDFOUNTPATH=C:\WINDOWS\Fonts');
$fontname='arial';
do
{
$font_size--;
//find out the size of the text at that font size
$bbox=imagettfbbox($font_size,0,$fontname,$button_text);
$right_text=$bbox[2]; //right co-ordinate
$left_text=$bbox[0]; //left co-ordinate
$width_text=$right_text-$left_text; //how wide is it?
$height_text=abs($bbox[7]-$bbox[1]); //how tall is it?
}while($font_size>8&&($height_text>$height_image_wo_margins||$width_text>$width_image_wo_margins));
if($height_text>$height_image_wo_margins||$width_text>$width_image_wo_margins)
{
//no readable font size will fit on button
echo 'Text given will not fit on button.<br />';
}
else
{
//we have found a font size that will fit,now work out where to put it
$text_x=$width_image/2.0-$width_text/2.0;
$text_y=$height_image/2.0-$height_text/2.0;
if($left_text<0)
$text_x+=abs($left_text); //add factor for left overhang
$above_line_text=abs($bbox[7]); //how far above the baseline?
$text_y+=$above_line_text; //add baseline factor
$text_y-=2; //adjustment factor for shape of our template
$white=imagecolorallocate($im,255,255,255);
imagettftext($im,$font_size,0,$text_x,$text_y,$white,$fontname,$button_text);
header('Content-type:image/png');
imagepng($im);
imagedestroy($im);
}
?>
运行时,显示:Warning: imagecreatefrompng(red-button.png) [function.imagecreatefrompng]: failed to open stream: No such file or directory in C:\AppServ\www\21\make_button.php on line 15
Could not create image.
如何办啊 展开
//check we have the variable data
//variable are button-text and color
$button_text=$_REQUEST['button_text'];
$color=$_REQUEST['color'];
if((empty($button_text)||empty($color))||(!($color=='red'||$color=='blue'||$color=='green')))
{
echo 'Could not create image - from not filled out correctly.';
exit;
}
//create an image of the right background and check size
$im=imagecreatefrompng($color.'-button.png');
if(!$im)
{
echo 'Could not create image.';
exit;
}
$width_image=imagesx($im);
$height_image=imagesx($im);
//out images need an 18 pixel margin in from the edge of the image
$width_image_wo_margins=$width_image-(2*18);
$height_image_wo_margins=$height_image-(2*18);
//work out if the font size will fit and makeit saller untili it does
//start out with the biggest size that will reasonably fit on ourt butons
$font_size=33;
//you need to tell GD2 where your fonts reside
putenv('GDFOUNTPATH=C:\WINDOWS\Fonts');
$fontname='arial';
do
{
$font_size--;
//find out the size of the text at that font size
$bbox=imagettfbbox($font_size,0,$fontname,$button_text);
$right_text=$bbox[2]; //right co-ordinate
$left_text=$bbox[0]; //left co-ordinate
$width_text=$right_text-$left_text; //how wide is it?
$height_text=abs($bbox[7]-$bbox[1]); //how tall is it?
}while($font_size>8&&($height_text>$height_image_wo_margins||$width_text>$width_image_wo_margins));
if($height_text>$height_image_wo_margins||$width_text>$width_image_wo_margins)
{
//no readable font size will fit on button
echo 'Text given will not fit on button.<br />';
}
else
{
//we have found a font size that will fit,now work out where to put it
$text_x=$width_image/2.0-$width_text/2.0;
$text_y=$height_image/2.0-$height_text/2.0;
if($left_text<0)
$text_x+=abs($left_text); //add factor for left overhang
$above_line_text=abs($bbox[7]); //how far above the baseline?
$text_y+=$above_line_text; //add baseline factor
$text_y-=2; //adjustment factor for shape of our template
$white=imagecolorallocate($im,255,255,255);
imagettftext($im,$font_size,0,$text_x,$text_y,$white,$fontname,$button_text);
header('Content-type:image/png');
imagepng($im);
imagedestroy($im);
}
?>
运行时,显示:Warning: imagecreatefrompng(red-button.png) [function.imagecreatefrompng]: failed to open stream: No such file or directory in C:\AppServ\www\21\make_button.php on line 15
Could not create image.
如何办啊 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询