Jump to content
SCH_001

Show a default image if image not found

Recommended Posts

Hi all in Frozen CE BS is there a way that if an image file is not found a default image can be shown

So just to clarify the image name and locate is set for the product but the image does not exist on the server can I have the page show a default image?

Change to below
image.png.1f1aec4703884508ed18dff00699b2c9.png
to this image.png.f5e54cfd7a09e1518d64da7bd9456b59.png

Share this post


Link to post
Share on other sites

I found this from 2014 and it seems to have done the job, any comments if the code should be improved for 2019

You need to modify the tep_image() function located in catalog/includes/function/html_output.php

Replace...

if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
  return false;
}

With...

if (!is_file($src)) {
$src = "images/no_image.jpg";
}

Share this post


Link to post
Share on other sites

I think you can do this with just css will show alt for any mising image. Test it first before using.

img
{
background-image:url('default.png');
width:400px;
}

 


 

Share this post


Link to post
Share on other sites

The better solution is to install the image thumbnailer addon. It does what you want but also, usually, improves the appearance and reduces the size of the images.

Share this post


Link to post
Share on other sites

Is this fall-out from a migration or an admin accident? Have you got image entries in the products/products_images table with no corresponding files?

I believe if an image tag relates to a non-existent image, you will always get the alt text - though forcing a background image might work behind it, my guess is that it would look bad.

Priority should be to put the images back in the place it's looking for them, or run a query against the database to update the entries to the new image path.

Backup plan: though a modification to the image function to check for image existence would work, the better approach would be a wrapper function for product images so you only get the overhead on those local files that might not exist. Faster function to check for local file existence is stream_resolve_include_path() instead of file_exists()


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce (Phoenix).

here: on the official osc download page

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Share this post


Link to post
Share on other sites

@BrockleyJohn Non of the above.
We deal in thousands of small parts for the products we have and at times we are just unable to locate images. We upload / update products using easy populate with the partnumber.jpg as the image name. We wget the images from the distributors and ftp them on to the server. Previously we would then go threw manualy updating the products which don't have images with our default no_image.jpg but now with the change above we no longer need to worry

Share this post


Link to post
Share on other sites

There is a very simple solution that could be built into the core to take care of this permanently by using "onerror".

<img src="https://www.jcmagpie.com/images/broken.jpg" alt="Oh no the image is broken" onerror="this.src='https://www.jcmagpie.com/images/jcmagpie-2.png';">

 


 

Share this post


Link to post
Share on other sites
1 hour ago, SCH_001 said:

@BrockleyJohn Non of the above.
We deal in thousands of small parts for the products we have and at times we are just unable to locate images. We upload / update products using easy populate with the partnumber.jpg as the image name. We wget the images from the distributors and ftp them on to the server. Previously we would then go threw manualy updating the products which don't have images with our default no_image.jpg but now with the change above we no longer need to worry

Sounds like your import should be doing all that automatically - get the file and store it, save instead noimage if it doesn't exist


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce (Phoenix).

here: on the official osc download page

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Share this post


Link to post
Share on other sites

use htaccess (based on site being in root directory)

<FilesMatch ".(jpg|png|gif)$">
ErrorDocument 404 /images/image-unavailable.gif
</FilesMatch>

 


App created for phoenix
TinyMCE editor for admin

 

Share this post


Link to post
Share on other sites
Posted (edited)
1 hour ago, Heatherbell said:

@Jack_mcs

I'm missing something - I see it can add a watermark to all images but I can't find how to add an image if no image exists in the instructions for the addon.

This works by default. Just upload the "no_image_available_150_150.gif" to your image folder and replace it with a custom no image pic if you wish.

Edited by raiwa

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×