PHP+GD creating random black thumbnails

落花浮王杯 提交于 2019-12-06 16:04:00

Most likely your passing a non JPEG image.

A JPEG is re-sized fine, however as the function can't read a different image format, this produces an invalid image. The result is a blank image, i.e. all zeros, this gives a black image. created by

imagecreatetruecolor($newWidth, $newHeight);

when I've run you class passing it a PNG image file it gives these Warnings and creates a black image:

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'filename' is not a valid JPEG file
Warning: imagecopyresampled(): supplied argument is not a valid Image resource

most likely you have warning disable so you don't get these messages.

try using

imagecreatefromstring(file_get_contents(filename))

instead of

imagecreatefromjpeg(filename)

this way GD automatically detects the file type based on the file header for you.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!