【发布时间】:2013-05-17 17:53:12
【问题描述】:
我正在尝试调整图像大小并将其保存到我的服务器。我想出了如何从 URL 保存图像,但后来我想调整图像大小并将其保存在完全相同的位置。这是我目前正在使用的脚本。它正在保存图像,但调整大小不起作用。
$cover = $_POST['cover'];
$title = $_POST['title'];
$artist = $_POST['artist'];
$date = date('Y-m-d', strtotime($_POST['date']));
$url = $cover;
$save_name = $artist."_".$title.".jpg";
$save_name = str_replace(' ','',$save_name);
$save_directory = $_ENV["DOCUMENT_ROOT"]."/albums/images/art/";
if(is_writable($save_directory)) {
file_put_contents($save_directory . $save_name, file_get_contents($url));
} else {
exit("Failed to write to directory ".$save_directory);
}
$location = "http://www.MYURL.com/albums/images/art/".$save_name;
$sql = "INSERT INTO albums (artist, title, date, cover) VALUES ('".$artist."', '".$title."', '".$date."', '".$location."')";
mysql_query($sql);
include("resize-class.php");
$resizeObj = new resize($location);
$resizeObj -> resizeImage(150, 150, 'exact');
$resizeObj -> saveImage($save_name, 100);
我正在使用resize-class.php,我认为这会让事情变得简单,但它不起作用。我想我可能会混淆我的调整大小路径或输出路径,但我不完全确定。任何提示都会很有帮助
【问题讨论】:
-
好的,但是你使用save_name,它只有名字,你没有指出文件夹在哪里。 File.jpg(你用什么) /home/user/images/destiny/File.jpg 你应该用什么。检查文件是否没有保存在其他地方
-
试试这个也检查
gd是否安装if (extension_loaded('gd') && function_exists('gd_info')) { echo "<pre>"; var_dump(gd_info()); echo "</pre>"; } -
["GD 版本"]=> string(27) "捆绑(2.0.34 兼容)"