• [Mod] Auto image resize on upload v2.0.1 (2010-12-18) 4 0 5 1
Currently:  

Author Topic: [Mod] Auto image resize on upload v2.0.1 (2010-12-18)  (Read 614167 times)

0 Members and 2 Guests are viewing this topic.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Auto image resize on upload v2.0.1 (2010-12-18)
« on: February 20, 2003, 03:23:29 AM »
This MOD will resize uploaded by users images and thumbnails to Max. Image Width set in settings.
Working on v1.7 - v1.7.9


-----------------------------------------------
Files to edit:
member.php
includes/upload.php
admin/settings.php
lang/<yourlanguage>/admin.php

-----------------------------------------------


Step 1
Open /member.php

Find:
Code: [Select]
   if (!$uploaderror) {
Insert above (if u installed "MOD Annotation by SLL" then, u'll need do Step 7 too):
Code: [Select]
//--------------------------------------------
//--------- Auto Image Resizing --------------
//--------------------------------------------
    if ($config['auto_image'] && !$uploaderror)
    {
      if ($direct_upload)
      {
        $src = MEDIA_PATH."/".$cat_id."/".$new_name;
      }
      else
      {
        $src = MEDIA_TEMP_PATH."/".$new_name;
      }
      $do_resize = 0;
      if ($image_info = @getimagesize($src))
      {
        if ($image_info[2] > 0 && $image_info[2] < 4 && $image_info[0] > $config['max_image_width'] || $image_info[1] > $config['max_image_height'])
        {
          if (!function_exists("init_convert_options"))
          {
            require(ROOT_PATH.'includes/image_utils.php');
          }
          $convert_options = init_convert_options();
          if (!$convert_options['convert_error'])
          {
            $quality = intval($config['auto_image_quality']);
            $quality = ($quality >= 0 && $quality <= 100) ? $quality : 85;
            if (!resize_image($src, $quality, $config['max_image_width'], 1, $config['max_image_height']))
            {
              $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name;
              $uploaderror = 1;
            }
          }
        }
      }
    }
    if ($config['auto_thumbnail'] && !$uploaderror)
    {
      if ($direct_upload)
      {
        $src = THUMB_PATH."/".$cat_id."/".$new_name;
      }
      else
      {
        $src = THUMB_TEMP_PATH."/".$new_name;
      }
      $do_resize = 0;
      if ($image_info = @getimagesize($src))
      {
        if ($image_info[2] > 0 && $image_info[2] < 4 && $image_info[0] > $config['max_thumb_width'] || $image_info[1] > $config['max_thumb_height'])
        {
          if (!function_exists("init_convert_options"))
          {
            require(ROOT_PATH.'includes/image_utils.php');
          }
          $convert_options = init_convert_options();
          if (!$convert_options['convert_error'])
          {
            $quality = intval($config['auto_image_quality']);
            $quality = ($quality >= 0 && $quality <= 100) ? $quality : 85;
            if (!resize_image($src, $quality, $config['max_thumb_width'], 1, $config['max_thumb_height']))
            {
              $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name;
              $uploaderror = 1;
            }
          }
        }
      }
    }
//--- End Auto Image Resizing ----------------




Step 2
Open /includes/upload.php

Find:
Code: [Select]
   $this->max_height['media'] = $config['max_image_height'];
Insert below:
Code: [Select]
   $this->auto_image['media'] = $config['auto_image'];
    $this->auto_image['thumb'] = $config['auto_thumbnail'];



Step 2.2
Find:
Code: [Select]
   $this->image_size = @getimagesize($this->upload_file);
    $ok = 1;

Insert below:

Code: [Select]
    if ($this->auto_image[$this->image_type]) {
      return 1; //auto image is on, don't need check for anything else.
    }




Step 3
Open /admin/settings.php

Find:
Code: [Select]
 show_setting_row("upload_emails");
Insert below:
Code: [Select]
 show_setting_row("auto_image", "radio");
  show_setting_row("auto_image_quality");




Step 4
Open /lang/<yourlanguage>/admin.php

Find:
Code: [Select]
$setting['auto_thumbnail_quality'] = "Thumbnail quality<br /><span class=\"smalltext\">0 to 100</span>";
Insert below:
Code: [Select]
$setting['auto_image'] = "Auto-resize image";
$setting['auto_image_quality'] = "Auto-resize image quality";




Step 5
Download attached file below.

Unzip it and upload to your 4images ROOT dir.
Execute it http://yoursiteaddress/4images/install_autoimage.php




Step 6
Go to Admin Control Panel -> settings. Under Upload settings u should find new options. Make sure "Max. image size in KB" is set to a high enough number




Step 7
This step u'll need only if u installed MOD Annotation by SLL
All u need to do is move code of Annotation, that u added in member.php, move it below the code u added in Step 1


Step 8 (Added 19/09/04)
This is an optional step, u'd need it if u want resize images not only using max width value as dimention but also max height.
Install atleast Step 1.x from this fix:
[FIX] Max height has no affect when do image resize


Video tutorial for this mod:
http://www.asian-lady.org/tutors/resize-mod/resize-mod.html


Changes log

v2.0.1 (2010-12-18)
* Fixed: thumbnails not being resized by non-admins (re-do Step 2)

v2.0 (2010-12-12)
+ Added: thumbnails resize (more info and upgrade instructions here)

v1.0 (2004-??-??)
- First release

« Last Edit: December 18, 2010, 07:11:20 PM by V@no »
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline knuckles

  • Pre-Newbie
  • Posts: 5
    • View Profile
Almost works
« Reply #1 on: February 20, 2003, 04:50:09 AM »
/home/virtual/site56/fst/var/www/html/platinum/gallery/admin/settings.php on line 311

Line 311 is: show_setting_row("auto_image_quality");

But it looks fine, it must be cascading from somewhere else.

Offline knuckles

  • Pre-Newbie
  • Posts: 5
    • View Profile
Works
« Reply #2 on: February 20, 2003, 04:56:01 AM »
Had to write the following two lines by hand:

show_setting_row("auto_image", "radio");
show_setting_row("auto_image_quality");

one of them had/has hidden chars that where affecting the script.

Thanks!

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Re: [MOD] Auto image resize on upload.
« Reply #3 on: February 20, 2003, 06:38:28 AM »
Quote from: V@no
This MOD will resize uploaded by users images to Max. Image Width set in settings.

Question:

I'm assuming this means it will scale down images that exceed the width/height setting and not scale up images that are smaller than the settings.  

Is this correct?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Auto image resize on upload.
« Reply #4 on: February 20, 2003, 06:45:36 AM »
yes, that's correct, the script checks first if image bigger then max width or height, then resize it if so.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline SLL

  • Hero Member
  • *****
  • Posts: 585
    • View Profile
[Mod] Auto image resize on upload.
« Reply #5 on: February 20, 2003, 09:09:32 AM »
Very good idea, V@no! According to my experience, just 10% of users have some idea how to resize their images, so if they're trying to upload oversized photos, and gallery doesn't accept it, they just give up...

Offline IngoT

  • Newbie
  • *
  • Posts: 49
    • View Profile
[Mod] Auto image resize on upload.
« Reply #6 on: February 21, 2003, 12:58:48 AM »
Hallo V@ano,

I have an error message. This error is not always. Mostly with large pictures.

Warning: imagecreatefromjpeg: './data/media/4/168-6875_IMG.JPG' is not a valid JPEG file in /homepages/8/d13361873/htdocs/digitalfotograf/bilderkiste/includes/image_utils.php on line 71


Warning: imagecreatefromjpeg: './data/media/4/168-6875_IMG.JPG.bak' is not a valid JPEG file in /homepages/8/d13361873/htdocs/digitalfotograf/bilderkiste/includes/image_utils.php on line 71


Here cut out of the lines 67 - 75:

else {
    $thumb = imagecreate($width, $height);
  }
  $image_create_handle = "imagecreatefrom".$types[$image_info[2]];
  if ($image = $image_create_handle($src)) {
    if (defined('CONVERT_IS_GD2') && CONVERT_IS_GD2 == 1) {
      imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
    }
    else {


Do you have a solution for the problem?

CU Ingo.

Offline Ernesto Taseffa

  • Full Member
  • ***
  • Posts: 151
    • View Profile
[Mod] Auto image resize on upload.
« Reply #7 on: February 26, 2003, 04:37:57 PM »
.
« Last Edit: August 09, 2009, 01:14:16 AM by Ernesto Taseffa »

Offline tradertt

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
[Mod] Auto image resize on upload.
« Reply #8 on: February 28, 2003, 06:22:18 PM »
I am getting the same error too ... Although installed the mod but cannot work ... it seems that any thing that deals with converting of images .. there is a problem between windows and unix ...

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Auto image resize on upload.
« Reply #9 on: February 28, 2003, 10:25:43 PM »
Quote from: tradertt
I am getting the same error too ... Although installed the mod but cannot work ... it seems that any thing that deals with converting of images .. there is a problem between windows and unix ...

can u do any image manipulations from admin control panel? if not, then ask your host what wrong, it's really nothing to do with the script itself.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Ernesto Taseffa

  • Full Member
  • ***
  • Posts: 151
    • View Profile
[Mod] Auto image resize on upload.
« Reply #10 on: February 28, 2003, 11:20:11 PM »
.
« Last Edit: August 09, 2009, 01:13:56 AM by Ernesto Taseffa »

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Auto image resize on upload.
« Reply #11 on: March 01, 2003, 01:04:15 AM »
yes, that how this mod works...that was the simpliest way to do...:S

give me the alghoritm how to fix it, I'll fix the code ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline tradertt

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
[Mod] Auto image resize on upload.
« Reply #12 on: March 01, 2003, 05:46:59 AM »
Quote from: V@no
Quote from: tradertt
I am getting the same error too ... Although installed the mod but cannot work ... it seems that any thing that deals with converting of images .. there is a problem between windows and unix ...

can u do any image manipulations from admin control panel? if not, then ask your host what wrong, it's really nothing to do with the script itself.


Yes I can .. I can do the Auto Image Resize from my admin panel ... the one that is manually done .. but weird is cannot use your mod ...

Offline tradertt

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
[Mod] Auto image resize on upload.
« Reply #13 on: March 01, 2003, 05:50:20 AM »
Quote from: seffern
Hi V@no,

do you sleep also sometime?  :?:

I forgot to post today that I did not turned the "auto-resize-function" on in admin menu. I guess this was the reason for the error code above from 26.2.2003, since it disappeared...

So the current status is the one of this morning in the other thread. It resizes automatically the images, which exceed the max. restriction in the admin-menu.

But as far as I remember it just looks at the width restriction, not at the height restriction.

Dirk


Is there such a function to turn on in the admin menu? I cannto find the auto resize function ...

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
[Mod] Auto image resize on upload.
« Reply #14 on: March 01, 2003, 09:38:49 AM »
Quote from: tradertt

Is there such a function to turn on in the admin menu? I cannto find the auto resize function ...

huh?
if u can not find that in the settings, then, no wonder it doesnt work.... :?
check again step-by-step instructions.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)