Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Posts
    59
    Plugin Contributions
    0

    Default Automatic Resize of Uploaded Images?

    Not sure why Zencart doesn't do this - perhaps I'm missing something really basic in the configuration of the product - I admit I'm a newbie...

    In any event once I turned my customer loose with his store he started uploading HUGE images.

    He's not a computer geek and does not know how to resize images, he''s a business man but we use the Lightbox add-on and his images were taking over the screen, so I did a little digging around in the code last night and wrote this code this morning.

    On his site I've established a maximum image size of 600 x 800 - you can change it to anything you want. I'm running on a dedicated centos 5.7 box and have Image Magick installed (which I use to resize the images). This code only works for JPG files but could easily be conditionalized to test the file extension and do gifs also. My customers only uses jpgs.

    I don't profess to be a crackerjack programmer but I've written a decent amount of php over the years and it has always worked for me.

    The code below is a snippet from /YOURADMINFOLDER/includes/classes/upload.php

    look for this code:

    PHP Code:
              if ($this->message_location == 'direct') {
                
    $messageStack->add(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY,$this->filename), 'success');
              } else {
                
    $messageStack->add_session(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY,$this->filename), 'success');
              }

              return 
    true

    and replace it with:

    PHP Code:
              if ($this->message_location == 'direct') {
                
    $messageStack->add(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY,$this->filename), 'success');
              } else {
                
    $messageStack->add_session(sprintf(SUCCESS_FILE_SAVED_SUCCESSFULLY,$this->filename), 'success');
              }

    //        mod jjj 2/23/12 to resize uploaded images

            
    $theimage $this->destination $this->filename;
            
    $myimg ImageCreateFromJpeg($theimage);
            
    $theimagew imagesx($myimg);
            
    $theimageh imagesy($myimg);
            
    $thestring $theimage " width="$theimagew " height="$theimageh "\n\r";
            if ( (
    $theimagew 600) or ($theimageh 800) ) 
              {    
                
    $newwidth $theimagew;
                
    $newheight $theimageh;
                while ( (
    $newwidth 600) or ($newheight 800) )
                 {
                  
    $newwidth round ($newwidth .99);
                  
    $newheight round ($newheight .99);
                 }
              
    $syscmd "mogrify -resize "$newwidth "x" $newheight " " $theimage;    
              
    system($syscmd$retval);

            }
              return 
    true

  2. #2
    Join Date
    Nov 2011
    Posts
    59
    Plugin Contributions
    0

    Default Re: Automatic Resize of Uploaded Images

    in case you're wondering that $thestring is for - I had some debugging code in there originally that would append information to a text file and I forgot to remove that line before posting the code.

    :)

  3. #3
    Join Date
    Nov 2011
    Posts
    59
    Plugin Contributions
    0

    Default Re: Automatic Resize of Uploaded Images

    this code will do the trick to handle gifs and pngs

    PHP Code:
            $theimage $this->destination $this->filename;
            if (
    stristr($theimage,'.jpg')) { $myimg ImageCreateFromJpeg($theimage); }
            if (
    stristr($theimage,'.gif')) { $myimg ImageCreateFromGif($theimage); }
            if (
    stristr($theimage,'.png')) { $myimg ImageCreateFrompng($theimage); } 

 

 

Similar Threads

  1. Replies: 1
    Last Post: 31 Oct 2014, 11:48 PM
  2. Can I sell digital images, based on images uploaded by customer?
    By cuulblu in forum Customization from the Admin
    Replies: 1
    Last Post: 17 Oct 2012, 05:05 PM
  3. Automatic Product Image Resize
    By rboyle in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 29 Jun 2009, 05:40 AM
  4. FTP images don't resize proportionally, Admin uploaded pics do
    By monkeytown in forum General Questions
    Replies: 6
    Last Post: 17 Dec 2008, 10:30 PM
  5. automatic resize based on screen resolution like oscommerce
    By prizark in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 15 Oct 2007, 05:28 PM

Posting Permissions

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