GD功能不起作用

发布于 2024-10-06 12:38:34 字数 942 浏览 4 评论 0原文

我正在尝试为我的网站创建缩略图。我使用提取文件

   $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 库是否已启用,它是,所以简而言之,我不知道出了什么问题。

http://www.neuromanga.com/phpinfo.php

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.

http://www.neuromanga.com/phpinfo.php

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

守不住的情 2024-10-13 12:38:34

确保 GD 已正确安装并且该功能存在:

<pre>
<?
$arr = get_defined_functions();
sort($arr['internal']);
print_r($arr);
?>

也。尽管这“创建”了图像,但您仍然必须将其写入屏幕或文件才能使用它。在使用 imagecreatefrom[..whatever] 的状态下,它只是 Web 应用程序中当前状态的一个对象,尚未渲染出来以供存储或显示。为此,您需要做任何您要做的事情并使用 imagejpeg
imagegifimagepng 实际将对象渲染回某个目的地。您可以通过执行 echo $src_img 来测试它,它应该打印如下内容:Resource id #1

make sure GD is properly installed and the function exists:

<pre>
<?
$arr = get_defined_functions();
sort($arr['internal']);
print_r($arr);
?>

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

不羁少年 2024-10-13 12:38:34

确保您的 $source 路径正确。如果 $src_img 不是新图像,它是什么?

Make sure your path to $source is correct. What is $src_img if it's not a new image?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文