DEV Community

Cover image for Fix: Opencart cache images not generated
Segun Abisagbo
Segun Abisagbo

Posted on

Fix: Opencart cache images not generated

I spent some hours struggling with figuring out why images on my local copy of a live Opencart site were not being displayed. Opencart seemed to not generate the resized product images and store them in the cache folder.

After a long search, I found the answer. Images were not being generated because I had PHP8 installed locally, and in PHP8, the GD library uses a class object instead of a resource. Opencart was checking for a resource using is_resource()

The solution was simple; also check for class objects.

In system/library/image.php, replace

if (is_resource($this->image)) {
Enter fullscreen mode Exit fullscreen mode

with

if (is_resource($this->image) || is_object($this->image)) {
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay