Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+20 votes
1.4k views
in Q2A Core by

After I updated PHP to version 8, avatars are no longer visible in my website, nor can users upload them, see animation below:
Image illustrating GD extension issue that keeps users from uploading their avatars
It throws an error message that goes like this:

The image could not be read. Please upload one of: GIF, JPG, PNG

What should I do?

Q2A version: 1.8.5

3 Answers

+6 votes
by
 
Best answer

Change 1: Please, open qa-include/util/image.php with a text editor and replace this line of code:

if (is_resource($inimage)) {

with this one:

if (is_resource($inimage) || $inimage instanceof \GdImage) {

on line 96 and line 105

Because of this issue, resizing of images won’t work either so please, apply the following to changes as well.

Change 2: In qa-include/util/image.php, place the text cursor on line 157 and replace:

if (is_resource($newimage)) {

with this:

if (is_resource($newimage) || $newimage instanceof \GdImage) {

and save any change.

Change 3: open qa-include/app/upload.php  and replace this line of code:

if (is_resource($image)) {

with this one:

if (is_resource($image) || $image instanceof \GdImage) {

on line 153, line 165, and line 174 (Note: remove the opening curly brace in this last case) and save any change.

This link will take you to a page with all these changes in just one place.

According to this PHP Watch’s article, "From PHP 8.0 and forward, GD extension uses \GdImage class objects instead of resources for its underlying data structures." And fortunately, this change is also backward compatible.


Tidbits

By the way, what is GD extension used for?
When PHP is compiled with the GD extension, PHP can also transform images. PHP’s official documentation (as of this writing) says “It can also be used to create and manipulate image files in a variety of different image formats, including GIF, PNG, JPEG, WBMP, and XPM. Even more conveniently, PHP can output image streams directly to a browser.

In the case of Question2Answer, GD extension is used for:

* and also resizing images as per the `Maximum size for storing avatars (in pixels)` option that is available under `Admin``Users`.


And you, what do you use the GD extension for? Leave your comments below Backhand index pointing down emoji

I hope it is useful.

by
Thanks man.........
by
+2
I've just seen this. I've also fixed this in a different way and sent the PR to the bugfix branch: https://github.com/q2a/question2answer/pull/906

I tried to avoid referencing the GdImage class... that seemed to have a chance to break things in the future.
by
edited by

Thank you (jair) for your explanation of the process of uploading users avatars. In fact, I benefited a lot after I modified the required according to the steps You set.

 Yes, this is the solution after upgrading to . php - 8

my regards

+3 votes
by
Thank you very much for this contribution.

I have been able to update to php 8. and not give me errors with these steps.

you are of importance to Q2A since few people today are interested in maintaining anything of quality within this environment.

Hopefully in a version 1.9 these changes are taken into account.

A great contribution.

Regards.
by
+1
Thank you @Monkey for your kind words, these are other PHP-8-related fixes:
https://www.question2answer.org/qa/91602/mod_fcgid-stderr-php-fatal-error-uncaught-typeerror
by
Right now I look at them and implement .yes or yes.
...