GD功能不起作用
我正在尝试为我的网站创建缩略图。我使用提取文件
$chapterZip = new ZipArchive();
if ($chapterZip->open($_FILES['chapterUpload']['tmp_name']))
{
if($chapterZip->extractTo("Manga/".$_POST['mangaName']."/".$_POST['chapterName']))
{
for($i = 0; $i < $chapterZip->numFiles; $i++) {
,然后循环遍历图像,并使用第一个图像将路径发送到此方法,
function createthumb($source,$output,$new_w,$new_h)
所有值都会被精细读取,直到我尝试使用以下代码
if (preg_match("/jpg|jpeg/",$ext)){$src_img=imagecreatefromjpeg($source);}
if (preg_match("/png/",$ext)){$src_img=imagecreatefrompng($source);}
if (preg_match("/gif/",$ext)){$src_img=imagecreatefromgif($source);}
满足正则表达式的先决条件文件和代码正在运行,但 imagecreate 函数没有创建新文件,我检查了 phpinfo 文件以查看 GD 库是否已启用,它是,所以简而言之,我不知道出了什么问题。
I'm trying to create a thumbnail images for my website. I extract the files using
$chapterZip = new ZipArchive();
if ($chapterZip->open($_FILES['chapterUpload']['tmp_name']))
{
if($chapterZip->extractTo("Manga/".$_POST['mangaName']."/".$_POST['chapterName']))
{
for($i = 0; $i < $chapterZip->numFiles; $i++) {
and then loop through the images and with the first image I send the path to a this method
function createthumb($source,$output,$new_w,$new_h)
all the values are read in fine up until I try to use the following code
if (preg_match("/jpg|jpeg/",$ext)){$src_img=imagecreatefromjpeg($source);}
if (preg_match("/png/",$ext)){$src_img=imagecreatefrompng($source);}
if (preg_match("/gif/",$ext)){$src_img=imagecreatefromgif($source);}
the prerequisite for the regular expression is being met by the file and the code is being ran, yet the imagecreate function doesn't create the new file, I checked my phpinfo file to see if the GD library is enable and it is, so in short I don't have a clue whats wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保 GD 已正确安装并且该功能存在:
也。尽管这“创建”了图像,但您仍然必须将其写入屏幕或文件才能使用它。在使用 imagecreatefrom[..whatever] 的状态下,它只是 Web 应用程序中当前状态的一个对象,尚未渲染出来以供存储或显示。为此,您需要做任何您要做的事情并使用 imagejpeg
或 imagegif 或 imagepng 实际将对象渲染回某个目的地。您可以通过执行
echo $src_img
来测试它,它应该打印如下内容:Resource id #1
make sure GD is properly installed and the function exists:
also. Although this "creates" the image, you still have to write it to either the screen or a file to be able to use it. at the state it's in using imagecreatefrom[..whatever] it's just a object in your current state in your web app and has not been rendered out for storage or display. for that you need to do whatever you're going to do and use imagejpeg
or imagegif or imagepng to actually render the object back out to some destination. you can test this by executing
echo $src_img
which should print something like:Resource id #1
确保您的 $source 路径正确。如果 $src_img 不是新图像,它是什么?
Make sure your path to $source is correct. What is $src_img if it's not a new image?