duanpin5168 2019-08-19 12:50
浏览 117

GDLib / ImageCreateFromPNG - 仅导致黑屏

When using the command imagecreatefrompng('source.png'), my browsers will not display any images. Google Chrome shows a big black screen with a small 16*16 square in the center and Microsoft Edge tries to download an image that cannot be displayed.

When opening a jpg with the command imagecreatefromjpg, the codes do seem to function.

I have no idea whats going wrong, even when straight up copying the code from my sources.

I have been using various sources, such as:

https://www.codepunker.com/blog/how-to-merge-png-files-with-php-and-GD-Library

Note: No errors are being displayed.

As per request, I have been using the exact code as my source:

<?php 
        // https://www.codepunker.com/blog/how-to-merge-png-files-with-php-and-GD-Library
            //define the width and height of our images
            define("WIDTH", 200);
            define("HEIGHT", 200);

            $dest_image = imagecreatetruecolor(WIDTH, HEIGHT);

            //make sure the transparency information is saved
            imagesavealpha($dest_image, true);

            //create a fully transparent background (127 means fully transparent)
            $trans_background = imagecolorallocatealpha($dest_image, 0, 0, 0, 127);

            //fill the image with a transparent background
            imagefill($dest_image, 0, 0, $trans_background);

            //take create image resources out of the 3 pngs we want to merge into destination image
            $a = imagecreatefrompng('1.png');
            $b = imagecreatefrompng('2.png');
            $c = imagecreatefrompng('3.png');

            //copy each png file on top of the destination (result) png
            imagecopy($dest_image, $a, 0, 0, 0, 0, WIDTH, HEIGHT);
            imagecopy($dest_image, $b, 0, 0, 0, 0, WIDTH, HEIGHT);
            imagecopy($dest_image, $c, 0, 0, 0, 0, WIDTH, HEIGHT);

            //send the appropriate headers and output the image in the browser
            header('Content-Type: image/png');
            imagepng($dest_image);

            //destroy all the image resources to free up memory
            imagedestroy($a);
            imagedestroy($b);
            imagedestroy($c);
            imagedestroy($dest_image);
    ?>

I have also checked my phpinfo(), all GD types have been enabled on my Xampp server.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧