我正在创建图像并尝试保存文件。图像创建很好,但我正在努力保存图像。
我在使用imagepng()进行简单尝试保存图像时收到的错误是'图片“https://examplemydomain.com/email/tweet.image.php”无法显示,因为它包含错误。'我将域名设置为chmod 777。
我已尝试创建另一个文件来调用图像,但这也不起作用 例如:tweet.image.save.php
<?php
$url = $_SERVER['DOCUMENT_ROOT'].'/email/tweet.image.php'; // your url here
$data = file_get_conents($url);
file_put_conents($_SERVER['DOCUMENT_ROOT'].'/email/tweet.png', $data);
?>
图像创建示例:tweet.image.php
<?php
//ini_set('display_errors',1);
//error_reporting(E_ALL);
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/twitter.php');
$color = RgbfromHex('FFFFFF');
$text = "This is an example tweet for noise agency ltd. I hope it shows up in less than 140 characters and does not overrun on to new lines. looks ok";
$text_length = 75;
$sig = wordwrap($text, $text_length, "<br />", true);
$font = '../fonts/arial.ttf';
$im = imagecreatetruecolor(402, 33);
$bg_color = imagecolorallocate($im, 88,158,214);
$font_color = imagecolorallocate($im, $color[0], $color[1], $color[2]);
imagefilledrectangle($im, 0, 0, 402, 33, $bg_color);
$text = str_replace('<br />', "\n", $sig);
$counttext = strlen($sig);
if ($counttext > 75) {
$startpos = 12;
} else {
$startpos = 20;
}
imagettftext($im, 9.1, 0, 0, $startpos, $font_color, $font, $text);
$filename = "tweet";
$directory = $_SERVER['DOCUMENT_ROOT']."/email/".$filename.".png";
chmod($directory,0755);
imagepng($im, $directory, 0, NULL);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
function RgbfromHex($hexValue) {
if(strlen(trim($hexValue))==6) {
return array(
hexdec(substr($hexValue,0,2)), // R
hexdec(substr($hexValue,2,2)), // G
hexdec(substr($hexValue,4,2)) // B
);
}
else return array(0, 0, 0);
}
?>
有人能指出我正确的方向吗?
非常感谢