osCmax v2.5 User Manual
Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Automatically scaled thumbs (2.0.25)

This is a discussion on Automatically scaled thumbs (2.0.25) within the osCMax v2 Features Discussion forums, part of the osCmax v2.0 Forums category; For version 2.0.25 if you upload a picture through the new product page of the admin interface, it will be ...

      
  1. #1
    New Member
    Join Date
    Aug 2009
    Posts
    5
    Rep Power
    0


    Default Automatically scaled thumbs (2.0.25)

    For version 2.0.25 if you upload a picture through the new product page of the admin interface, it will be automatically scaled to a thumb (in thumbs directory). This happens neatly if in Configuration > Images, the "Product Image Width" is set and "Calculate Image Size" is set to true (with "Product Image Height" left blank).

    If I set "Product Image Height" and leave "Product Image Width" blank, then the thumbnail image in the thumbnails directory is not automatically scaled.

    Is there a setting somewhere that I may have missed?

  2. #2
    osCMax Development Team
    ridexbuilder's Avatar
    Join Date
    Jul 2008
    Location
    Haggisland
    Posts
    3,014
    Rep Power
    36


    Talking Re: Automatically scaled thumbs (2.0.25)

    Quote Originally Posted by MAxISD View Post
    For version 2.0.25 if you upload a picture through the new product page of the admin interface, it will be automatically scaled to a thumb (in thumbs directory). This happens neatly if in Configuration > Images, the "Product Image Width" is set and "Calculate Image Size" is set to true (with "Product Image Height" left blank).

    If I set "Product Image Height" and leave "Product Image Width" blank, then the thumbnail image in the thumbnails directory is not automatically scaled.

    Is there a setting somewhere that I may have missed?
    Quote Originally Posted by ridexbuilder
    What do you mean by "scaled"? This is where most people get confused - generally it's folks who watch widescreen TV in the wrong aspect ratio - like old squashed up Westerns or newsreaders looking like wide-mouthed frogs.
    When you scale an oblong image, you will still end up with an oblong image. When you scaled a square image, you get a square image. Simple.
    It can't miraculously take a rectangle and add borders to produce a square (at least no-one has paid me to write the routine ), or crop arbitrarily into a square. [A touch of arithmetic can fairly easily add a border to a rectangular image, using Irfanview].
    Having said all that, the routine was written with fixed width in mind (variable height). This is how most people lay out their images but given sufficient incentive, I may revisit and add fixed height. I've had a quick look but requires a bit more time and more importantly testing - other priorities

    EJ
    Last edited by ridexbuilder; 06-29-2010 at 08:21 AM.
    Hosting plans with installation, configuration, contributions, support and maintenance.

  3. #3
    New Member
    Join Date
    Aug 2009
    Posts
    5
    Rep Power
    0


    Default Re: Automatically scaled thumbs (2.0.25)

    You are right. I should have written "resized" iso "scaled". Fixed image height would be nice for products shown in rows.

  4. #4
    osCMax Development Team
    ridexbuilder's Avatar
    Join Date
    Jul 2008
    Location
    Haggisland
    Posts
    3,014
    Rep Power
    36


    Wink Re: Automatically scaled thumbs (2.0.25)

    In theory, it's pretty simple to implement (as long as folks don't put in both sizes - I even noted it so, in the text description but still see it done). A quick and dirty way is to change width to height in the phpthumb file. I did take a decent look yesterday but other things on my mind and got in a muddle.
    Hosting plans with installation, configuration, contributions, support and maintenance.

  5. #5
    New Member
    Join Date
    Aug 2009
    Posts
    5
    Rep Power
    0


    Default Re: Automatically scaled thumbs (2.0.25)

    I can give it a try. Which file is that exactly?

  6. #6
    osCMax Development Team
    ridexbuilder's Avatar
    Join Date
    Jul 2008
    Location
    Haggisland
    Posts
    3,014
    Rep Power
    36


    Default Re: Automatically scaled thumbs (2.0.25)

    The file is in the process of being updated for 2.1; please try this (untested) version and report back on success/failure:

    Replacement catalog/admin/includes/functions/instant_update.php

    EJ
    Attached Files Attached Files
    Hosting plans with installation, configuration, contributions, support and maintenance.

  7. #7
    New Member
    Join Date
    Aug 2009
    Posts
    5
    Rep Power
    0


    Default Re: Automatically scaled thumbs (2.0.25)

    I can't open the zip. It seems to be corrupt. Could you post it again?

  8. #8
    osCMax Development Team
    ridexbuilder's Avatar
    Join Date
    Jul 2008
    Location
    Haggisland
    Posts
    3,014
    Rep Power
    36


    Arrow Re: Automatically scaled thumbs (2.0.25)

    Mickey Mouse Operating System (Windoze)?
    Actually there's an error with the code....
    Last edited by ridexbuilder; 06-30-2010 at 10:39 AM.
    Hosting plans with installation, configuration, contributions, support and maintenance.

  9. #9
    osCMax Development Team
    ridexbuilder's Avatar
    Join Date
    Jul 2008
    Location
    Haggisland
    Posts
    3,014
    Rep Power
    36


    Lightbulb Re: Automatically scaled thumbs (2.0.25)

    Appears to work now - minimal testing and not elegant.
    PHP Code:
    <?php
    /*
        Specify Fixed Product Image Height or Width
        Ridexbuilder - http://ejsolutions.co.uk
        osCMax 2010
        Released under GPL
    */
      
    $images_dir DIR_WS_IMAGES// default catalog images folder;
      
    $exclude_folders = array("banners","default","icons","mail","infobox","js"); // folders to exclude from adding new images
      
    $root_images_dir DIR_FS_CATALOG .  $images_dir DYNAMIC_MOPICS_BIGIMAGES_DIR;
      
    $root_thumbs DIR_FS_CATALOG $images_dir DYNAMIC_MOPICS_THUMBS_DIR;
      
    $html_images_dir =  DIR_WS_CATALOG .  $images_dir DYNAMIC_MOPICS_BIGIMAGES_DIR;
      
    $html_thumbs =  DIR_WS_CATALOG .  $images_dir DYNAMIC_MOPICS_THUMBS_DIR;  
      
    $new_dir preg_replace('/[^a-zA-Z0-9_.-]/i''_',$_POST['new_directory']); 
      
    $dir = (tep_not_null($new_dir) ? $new_dir $_POST['directory']);
     
    // instant update    
       
    if ($action == 'new_product_preview') {

    // copy image only if modified
            
    if ($dir && !is_dir($root_images_dir $dir)) { 
                       if (
    mkdir($root_images_dir $dir)) $messageStack->add('Folder ' $dir ' created in '$root_images_dir '.''success');
                    }
            if (
    $dir && !is_dir($root_thumbs $dir)) { 
                       if (
    mkdir($root_thumbs $dir)) $messageStack->add('Folder ' $dir ' created in '$root_thumbs '.''success');
                    }                
            
    $products_image = new upload('products_image');
            
    $products_image->set_destination($root_images_dir . ($dir $dir .'/' ''));
            
            if (
    $products_image->parse() && $products_image->save()) {
                
    $products_image_name =  ($dir $dir '/' '') . $products_image->filename;
            require_once( 
    DIR_FS_CATALOG 'ext/phpthumb/phpthumb.class.php');

    // create phpThumb object
            
    $phpThumb = new phpThumb();
            if (
    PRODUCT_IMAGE_WIDTH !='') {
                
    // create 2 sizes of 'thumbnail' based on width
                // Note: thumbnail referenced below applies to both image sizes.
                
    $thumbnails = array(PRODUCT_IMAGE_WIDTH => $root_thumbsPOPUP_IMAGE_WIDTH => $root_images_dir);
                foreach (
    $thumbnails as $thumbnail_width => $dest_dir) {
                    
    // this is very important when using a single object to process multiple images
                    
    $phpThumb->resetObject();

                    
    // set data source -- do this first, any settings must be made AFTER this call
                    
    if (is_uploaded_file(@$_FILES['userfile']['tmp_name'])) {
                    
    $phpThumb->setSourceFilename($_FILES['userfile']['tmp_name']);
                    
    $output_filename $dest_dir $dir .basename($_FILES['userfile']['name']).'_'.$thumbnail_width.'.'.$phpThumb->config_output_format;
                    } else {
                    
    $phpThumb->setSourceData(file_get_contents($root_images_dir $products_image_name));
                    
    $output_filename $dest_dir $products_image_name;
                    }

                    
    // set parameters (see "URL Parameters" in phpthumb.readme.txt)
                    
    $phpThumb->setParameter('config_cache_directory'DIR_FS_CATALOG 'cache/'); //doesn't work!
                    
    $phpThumb->setParameter('w'$thumbnail_width);
                    if (
    $dest_dir $root_images_dir) { 
                        
    $phpThumb->setParameter('h'POPUP_IMAGE_HEIGHT);  //specify max height for popup
                        
    $phpThumb->setParameter('q'90);  //maintain higher quality for popup
                    
    }

                    
    // generate & output thumbnail
                    
    if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
                        
    if ($phpThumb->RenderToFile($output_filename)) {
                        
    // do something on success
                        
    } else {
                        
    // do something with debug/error messages
                        
    echo 'Failed:<pre>'.implode("nn"$phpThumb->debugmessages).'</pre>';
                        }
                    } else {
                    
    // do something with debug/error messages
                    
    echo 'Failed:<pre>'.$phpThumb->fatalerror."nn".implode("nn"$phpThumb->debugmessages).'</pre>';
                    }
                }
            } else {
                
    // create 2 sizes of 'thumbnail' based on height
                // Note: thumbnail referenced below applies to both image sizes.
                
    $thumbnails = array(PRODUCT_IMAGE_HEIGHT => $root_thumbsPOPUP_IMAGE_HEIGHT => $root_images_dir);
                foreach (
    $thumbnails as $thumbnail_height => $dest_dir) {
                    
    // this is very important when using a single object to process multiple images
                    
    $phpThumb->resetObject();

                    
    // set data source -- do this first, any settings must be made AFTER this call
                    
    if (is_uploaded_file(@$_FILES['userfile']['tmp_name'])) {
                    
    $phpThumb->setSourceFilename($_FILES['userfile']['tmp_name']);
                    
    $output_filename $dest_dir $dir .basename($_FILES['userfile']['name']).'_'.$thumbnail_height.'.'.$phpThumb->config_output_format;
                    } else {
                    
    $phpThumb->setSourceData(file_get_contents($root_images_dir $products_image_name));
                    
    $output_filename $dest_dir $products_image_name;
                    }

                    
    // set parameters (see "URL Parameters" in phpthumb.readme.txt)
                    
    $phpThumb->setParameter('config_cache_directory'DIR_FS_CATALOG 'cache/'); //doesn't work!
                    
    $phpThumb->setParameter('h'$thumbnail_height);
                    if (
    $dest_dir $root_images_dir) { 
                        
    $phpThumb->setParameter('w'POPUP_IMAGE_WIDTH);  //specify max width for popup
                        
    $phpThumb->setParameter('q'90);  //maintain higher quality for popup
                    
    }

                    
    // generate & output thumbnail
                    
    if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
                        
    if ($phpThumb->RenderToFile($output_filename)) {
                        
    // do something on success
                        
    } else {
                        
    // do something with debug/error messages
                        
    echo 'Failed:<pre>'.implode("nn"$phpThumb->debugmessages).'</pre>';
                        }
                    } else {
                    
    // do something with debug/error messages
                    
    echo 'Failed:<pre>'.$phpThumb->fatalerror."nn".implode("nn"$phpThumb->debugmessages).'</pre>';
                    }
                }        
            }
    // end thumbnail creation                
            
    } else {
              
    $products_image_name = (isset($HTTP_POST_VARS['products_previous_image']) ? $HTTP_POST_VARS['products_previous_image'] : '');
            }

        if (
    $_POST['instant_update'] == 'on') { 
          
    $_POST['products_image'] = stripslashes($products_image_name);
            
    $action = (isset($_GET['pID']) ? 'update_product' 'insert_product');  
        }
    }
    ?>
    Thanks button and beer money donations always gratefully received.
    Hosting plans with installation, configuration, contributions, support and maintenance.

  10. #10
    New Member
    Join Date
    Aug 2009
    Posts
    5
    Rep Power
    0


    Default Re: Automatically scaled thumbs (2.0.25)

    That resizes images with fixed height nicely!
    Thanks a lot!

Page 1 of 2 12 LastLast

Similar Threads

  1. tax calculates itself automatically
    By MrE03 in forum osCmax v2 Installation issues
    Replies: 2
    Last Post: 10-08-2006, 10:00 PM
  2. Cannot get main thumbnail to pull from 'thumbs' directory
    By groggory in forum osCMax v2 Features Discussion
    Replies: 2
    Last Post: 02-09-2006, 12:42 PM
  3. mopics /thumbs path problems
    By miahac in forum osCMax v2 Features Discussion
    Replies: 5
    Last Post: 09-23-2005, 04:48 PM
  4. Automatically show Sub Categories?
    By darrell in forum osCommerce 2.2 Modification Help
    Replies: 1
    Last Post: 08-13-2004, 06:48 AM
  5. Problem with MoPics, changes thumbs directory
    By EddyXP in forum osCmax v1.7 Discussion
    Replies: 13
    Last Post: 07-25-2004, 09:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •