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)) {
with
if (is_resource($this->image) || is_object($this->image)) {
Top comments (1)
A useful troubleshooting case, especially for developers maintaining older OpenCart installations while moving to newer PHP versions. The PHP 8 compatibility difference in GD can be easy to overlook, and this is a good example of how seemingly unrelated environment changes can break image processing. Compatibility checks like this are worth including when migrating legacy eCommerce projects to newer PHP versions.