php GD问题,创建黑色图像
我已经为此烦恼了几个小时,我正在为 magento 开发一个图像裁剪模块,它在我的本地主机上运行良好,但是当我在线上传文件时,它不起作用! gd 创建一个黑色图像。
我尝试了一切..检查了权限、文件路径,并且没有显示任何错误..
这是创建图像的代码,
<?php
$id = $_GET['id'];
$crop = $_GET['crop'];
$token = $_GET['token'];
if ($id !== '' && $crop !== '') {
$crop = explode(":", $crop);
$product = Mage::getModel('catalog/product')->load($id);
$file = $product->getMediaConfig()->getMediaUrl($product->getImage());
$src = $file;
$targ_w = $crop[0];
$targ_h = $crop[1];
$img_r = imagecreatefromjpeg($src);
$dst_r = imagecreatetruecolor( $crop[6], $crop[7] );
imagecopyresampled($dst_r,$img_r, 0,0, $crop[2],$crop[3], $crop[6],$crop[7], $crop[6],$crop[7]);
$dir = '../truecolor/images/'.$id.'/test/';
if (!file_exists($dir)) {
mkdir($dir, 0777);
}
$filename = '../truecolor/images/'.$id.'/test/sw_'.$id.'.jpg';
if (file_exists($filename)) {
unlink($filename);
}
imagejpeg($dst_r,$filename,100);
?>
非常感谢任何帮助。.
已解决:
好的我想通了,我觉得有点愚蠢:)
我正在使用的服务器有一个http身份验证,这阻止了php文件加载图像..
现在工作正常!
i'v been pulling my hair over this for a couple of hours now, i am working on an image cropping module for magento, it works fine on my localhost but when i upload the file online it doesn't work! gd creates a black image.
i'v tried everything.. checked permission, file paths, and it doesn't show any errors..
here is the code that creates the image
<?php
$id = $_GET['id'];
$crop = $_GET['crop'];
$token = $_GET['token'];
if ($id !== '' && $crop !== '') {
$crop = explode(":", $crop);
$product = Mage::getModel('catalog/product')->load($id);
$file = $product->getMediaConfig()->getMediaUrl($product->getImage());
$src = $file;
$targ_w = $crop[0];
$targ_h = $crop[1];
$img_r = imagecreatefromjpeg($src);
$dst_r = imagecreatetruecolor( $crop[6], $crop[7] );
imagecopyresampled($dst_r,$img_r, 0,0, $crop[2],$crop[3], $crop[6],$crop[7], $crop[6],$crop[7]);
$dir = '../truecolor/images/'.$id.'/test/';
if (!file_exists($dir)) {
mkdir($dir, 0777);
}
$filename = '../truecolor/images/'.$id.'/test/sw_'.$id.'.jpg';
if (file_exists($filename)) {
unlink($filename);
}
imagejpeg($dst_r,$filename,100);
?>
would really appreciate any help with this..
SOLVED:
Ok i figured it out, and i feel kinda stupid :)
the server i was working on had an http authentication, which was preventing the image from being loaded by the php file..
works fine now!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论