【发布时间】:2017-02-20 03:56:55
【问题描述】:
解决了问题!!!
-
1234563 > 为了获得高质量的图片
图像文件夹没有斜线“images/fb/”
对于
imagecolorallocateimagecolorallocate($im, 142, 011, 029)三位数RGB 也可以得到正确的输出。
所以,下面给出了这个问题的答案和完整的代码
<?php
// Create image with 2 line of text
$im = imagecreatetruecolor(600, 300);
$text_color = imagecolorallocate($im, 142, 011, 029);
imagestring($im, 10, 5, 5, 'Some Text String', $text_color);
imagestring($im, 10, 5, 50, 'Some Text String 2', $text_color);
// Set the content type header as image/jpeg
header('Content-Type: image/jpeg');
// Output the image
//imagejpeg($im); //up-to this point its working well
$name="test2";
$save = "images/fb/". strtolower($name) .".jpeg";
imagejpeg($im, $save, 100); //Saves the image
imagejpeg($im); //Displays the image
// Free up memory
imagedestroy($im);
?>
问题
请帮我解决这个问题,
我正在尝试通过 php 创建图像并尝试将创建的图像存储在文件夹中,图像确实显示了,但是当我将保存添加到文件夹时它给了我错误。以下是我尝试过的代码。
<?php
// Create image with 2 line of text
$im = imagecreatetruecolor(600, 300);
$text_color = imagecolorallocate($im, 142, 11, 29);
imagestring($im, 10, 5, 5, 'Some Text String', $text_color);
imagestring($im, 10, 5, 50, 'Some Text String 2', $text_color);
// Set the content type header as image/jpeg
header('Content-Type: image/jpeg');
// Output the image
//imagejpeg($im); //up-to this point its working well
$name="test";
$save = "/images/fb/". strtolower($name) .".jpeg";
imagejpeg($im, $save, 0, NULL);
// Free up memory
imagedestroy($im);
?>
以下是我遇到的错误
The image "path" cannot be displayed because it contains errors.
我的文件夹结构是
->www
-> projectFolder
-> subFolder
->phpFile
->imageFolder (images)
->imageSubFolder (fb)
我也尝试过chmod,但它的权限似乎不是问题,因为我正在 Localhost 中尝试这个。
任何建议将不胜感激......
【问题讨论】:
-
您确定路径
/images/fb/存在吗?/表示这是服务器上的主文件夹,而不是您本地的images/fb/文件夹 -
也许你的路径错了?什么错误?
-
"...它给了我错误" ...错误是什么?
-
$save = "/path/to/www/images/fb/". strtolower($name) .".jpeg";您需要使用完整的服务器路径,或者使用相对路径并省略图像前的斜线$save = "images/fb/". strtolower($name) .".jpeg"; -
我确实通过省略图像前面的 / 来尝试使用相对路径,但这没有帮助。