Jump to content
oscMarket

Dynamic thumbnails

Recommended Posts

In includes/html_output.php,

FIND:
 

////
// The HTML image wrapper function
  function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '', $responsive = true, $bootstrap_css = '') {
    if ( (empty($src) || ($src == 'images/')) && (IMAGE_REQUIRED == 'false') ) {
      return false;
    }

AFTER ADD:
 

    if (is_file($src) && tep_not_null($width) && tep_not_null($height)) {
        require_once('ext/gumlet/ImageResize.php');        

        if (!is_dir(DIR_FS_CATALOG . 'images/' . $width . 'x'. $height)) {
            mkdir(DIR_FS_CATALOG . 'images/' . $width . 'x'. $height, 0755, true);
        }
        $new_image = end(explode('/',$src));
        $path = 'images/' . $width . 'x'. $height . '/'. $new_image;
        if (!file_exists($path)){
            $OSCOM_Thumb = new ImageResize($src);
            $OSCOM_Thumb->resize($width,$height, true);
            $OSCOM_Thumb->save($path, true);
        }    
        if(file_exists($path)){
            $src = $path;
        }
    }

in ext create directory called gumlet
Within add the attached file:


 

ImageResize.php

Edited by wHiTeHaT

Share this post


Link to post
Share on other sites

Greetings,

 

Is there any way of overlaying a div over the tep_image() function call and trigger the colorbox in product_info.php?

It would be handy to overlay some css div for "out of stock" info, for example.

Best regards,

Luis Xavier

Share this post


Link to post
Share on other sites

@Owl Sauron 

Only a watermark
https://github.com/gumlet/php-image-resize
 

$image = new ImageResize('image.jpg');

// Add banner on bottom left corner
$image18Plus = 'banner.png'
$image->addFilter(function ($imageDesc) use ($image18Plus) {
    $logo = imagecreatefrompng($image18Plus);
    $logo_width = imagesx($logo);
    $logo_height = imagesy($logo);
    $image_width = imagesx($imageDesc);
    $image_height = imagesy($imageDesc);
    $image_x = $image_width - $logo_width - 10;
    $image_y = $image_height - $logo_height - 10;
    imagecopy($imageDesc, $logo, $image_x, $image_y, 0, 0, $logo_width, $logo_height);
});

 

Edited by wHiTeHaT

Share this post


Link to post
Share on other sites

Excellent addon @wHiTeHaT

I think it would be better to put everything together in a .ZIP and upload it as an addon to the market.
Here in the forum will be lost in a few days ....

Best regards

Valqui


I'm using oscommerce Edge v2.3.4.1

Get here the latest osCommerce Online Merchant Community Bootstrap Edition v2.3.4.1 CE

Share this post


Link to post
Share on other sites
20 hours ago, wHiTeHaT said:

Cool thumbnailscript, but it will throw many errors if the source image, for whatever reason, does not exist.

Do you have a fix for that?


:heart: osCommerce

I am using osCommerce version 2.3.4.1 CE  Frozen

 

Share this post


Link to post
Share on other sites
4 hours ago, Rwe said:

Cool thumbnailscript, but it will throw many errors if the source image, for whatever reason, does not exist.

 

Yeah... make sure it does.
 

But i changed the code from the first post, so you will not get any error for that anymore.

Edited by wHiTeHaT

Share this post


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

so you will not get any error for that anymore.

 @wHiTeHaT Ok thanks, It still does if an image is missing:

Warning: finfo_file(images/dvd/speed.gif): failed to open stream: No such file or directory in  xxx..

Warning: getimagesize(images/dvd/speed.gif): failed to open stream: No such file or directory in xxx..

i changed 

        if ($filename === null || empty($filename) || (substr($filename, 0, 7) !== 'data://' && !is_file($filename))) {
            $this->error[] = 'File does not exist'; 
        }

to

        if ($filename === null || empty($filename) || (substr($filename, 0, 7) !== 'data://' && !is_file($filename))) {
            $this->error[] = 'File does not exist';
           $filename = 'images/no-image.png';
        }

Its working now with a no-image.png but maybe there is a better way of fixing this.


:heart: osCommerce

I am using osCommerce version 2.3.4.1 CE  Frozen

 

Share this post


Link to post
Share on other sites

Yes..... i made a mistake, but you should not change that code within the ImageResize.php.
just:
 

    if (is_file($src) && tep_not_null($width) && tep_not_null($height)) {
        require_once('ext/gumlet/ImageResize.php'); 


Post updated.

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

×