Resize pic on upload Resize pic on upload
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Resize pic on upload

Started by clifflui, October 13, 2003, 07:03:21 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

clifflui

We all know that we usually have to resize a picture (e.g. 1280x1024) to a reasonable size (e.g. 600x480) before uploading via FTP or web interface.

Would it not be great to have an option checkbox in the web interface to resize (by limiting height/width or percentage magnification) the image that one plans to upload so we do not have to hassle with photoshop?

As for batch uploads, you can have an option to resize all by limiting dimensions or by percentage.

Joachim Müller

There's already a tool integrated in version 1.2.0 (that will come out soon) that can drop the fullsize pics after upload (freeing a lot of webspace). We've also already considered the feature you're suggesting for a future version of Coppermine (a resize of the uploaded picture to a max dimension the site admin has set in config).
At the moment, site admins are encouraged to upload multiple pics by ftp (with the pics already resized to the fnal version they want it to appear in), using the batch-add function. The upload by browser interface is only recommended for "normal" users who can't have ftp access; most of them hardly know how to resize a pic properly before uploading.
In other words: we're working on it... :wink:

GauGau

clifflui

Ah, GauGau, nice to see coppermine up again. I guess I have to wait until version 2 comes out then. Thanks a bunch.

freez

That is were a tool like iBULC comes in handy. It will optional resize image images before upload. Try that out here: http://www.ibulc.com/demonstration/

phil

I finally found a nice freeware, which resizes and also renames the pictures with the EXIF data.
http://www.unidreamtech.com/  8)
Just download and install it

Have fun and enjoy life...
phil

Haelios

I'm just a newbie so I can't seem to understand why it is taking so long to add the full-sized-image-auto-resize feature. I mean, there is already code that creates the thumbnails and the normal images.

hyperion

@Haelios:

Where's the patch?  :wink:
"Then, Fletch," that bright creature said to him, and the voice was very kind, "let's begin with level flight . . . ."

-Richard Bach, Jonathan Livingston Seagull

(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fwww.mozilla.org%2Fproducts%2Ffirefox%2Fbuttons%2Fgetfirefox_small.png&hash=9f6d645801cbc882a52f0ee76cfeda02625fc537)

black1

I came up with my own quick hack for automatic resize on upload, which I'd like to share. Keep in mind it only works with GD version 2.x and on jpeg images:

edit db_input.php
find
chmod($uploaded_pic, octdec($CONFIG['default_file_mode']));
and insert this right below it
if (eregi ("\.jpe?g$", $uploaded_pic)) {
        $imgOld = imagecreatefromjpeg($uploaded_pic);
        $width = imagesx($imgOld);
        $height = imagesy($imgOld);
        if ($width > $CONFIG['picture_width']) {
                $height = ($CONFIG['picture_width']/$width)*$height;
                $width = $CONFIG['picture_width'];
                $imgNew = ImageCreateTrueColor($width,$height);    //requires GD 2.0
                ImageCopyResampled($imgNew,$imgOld,0,0,0,0,$width,$height,imagesx($imgOld),imagesy($imgOld));    //requires GD 2.0
                ImageJpeg($imgNew,$uploaded_pic);
                Imagedestroy($imgNew);
        }
}

enjoy   :wink:

Hal9000

Interesting code.
Hhowever, it's resizing pictures to the limit set for intermediate pictures (in my case 400).
I modified the code a bit to work with vertical pictures too (height>width) and changed the 'picture_width' value with 'max_upl_width_height' which is set to 800, so I am supposed to get 800x600 or 600x800 pictures, depending on the case.
However, pictures are still generated using 400 pixels not 800, i don't understand why.
Can anybody look into this? Here's the code:


// Resize picture automatically if it's too big - added by Hal9000
if (eregi ("\.jpe?g$", $uploaded_pic)) {
  $imgOld = imagecreatefromjpeg($uploaded_pic);
  $width = imagesx($imgOld);
  $height = imagesy($imgOld);
  if ($width >= $height && $width > $CONFIG['max_upl_width_height']) {
  $height = ($CONFIG['max_upl_width_height']/$width)*$height;
  $width = $CONFIG['max_upl_width_height'];
  $imgNew = ImageCreateTrueColor($width,$height);    //requires GD 2.0
  ImageCopyResampled($imgNew,$imgOld,0,0,0,0,$width,$height,imagesx($imgOld),imagesy($imgOld));    //requires GD 2.0
  ImageJpeg($imgNew,$uploaded_pic);
  Imagedestroy($imgNew);
  }
  if ($width < $height && $height > $CONFIG['max_upl_width_height']) {
  $width = ($CONFIG['max_upl_width_height']/$height)*$width;
  $height = $CONFIG['max_upl_width_height'];
  $imgNew = ImageCreateTrueColor($width,$height);    //requires GD 2.0
  ImageCopyResampled($imgNew,$imgOld,0,0,0,0,$width,$height,imagesx($imgOld),imagesy($imgOld));    //requires GD 2.0
  ImageJpeg($imgNew,$uploaded_pic);
  Imagedestroy($imgNew);
  }
}



Thanks!
hal

Hal9000

I'm an idiot, WinSCP got disconnected and I didn't notice, so i was saving the php file to nowhere and it didn't update hehe...
My modified code works wonderfully, I recommend it!!!
It resizes correctly both horizontal and vertical images, using the "Max width or height for uploaded pictures (pixels)" setting from the config.
Greetings! And thanks to black1 of course ;)

RatKing

An other solution to the same problem (it just doesn't change batch added pictures...)

http://forum.coppermine-gallery.net/index.php?topic=6281.0

stcrim

I'm using ImageMagick - has anyone created a hack that will resize using it on upload?

Steve

spaceman

Quote from: stcrim on June 22, 2004, 04:21:31 AM
I'm using ImageMagick - has anyone created a hack that will resize using it on upload?

Steve

http://www.imagemagick.org/www/mogrify.html

I'm a coppermine newbie, but a semi-ex php/mysql programmer, and we've been using the ImageMagick mogrify command to automatically resize user uploaded jpegs in our CMS for about 3 years now. For someone who knows ImageMagick code this should be child's play :-)

I'd seriously like to see the 'intermediate + thumbnails file being kept the and the user's original (large) file discarded (as per this forum member: http://forum.coppermine-gallery.net/index.php?topic=6206.0 ).
www.itomic.com - perth business website solutions

HighlanderBR


// Resize picture automatically if it's too big - added by Hal9000
if (eregi ("\.jpe?g$", $uploaded_pic)) {
  $imgOld = imagecreatefromjpeg($uploaded_pic);
  $width = imagesx($imgOld);
  $height = imagesy($imgOld);
  if ($width >= $height && $width > $CONFIG['max_upl_width_height']) {
  $height = ($CONFIG['max_upl_width_height']/$width)*$height;
  $width = $CONFIG['max_upl_width_height'];
  $imgNew = ImageCreateTrueColor($width,$height);    //requires GD 2.0
  ImageCopyResampled($imgNew,$imgOld,0,0,0,0,$width,$height,imagesx($imgOld),imagesy($imgOld));    //requires GD 2.0
  ImageJpeg($imgNew,$uploaded_pic);
  Imagedestroy($imgNew);
  }
  if ($width < $height && $height > $CONFIG['max_upl_width_height']) {
  $width = ($CONFIG['max_upl_width_height']/$height)*$width;
  $height = $CONFIG['max_upl_width_height'];
  $imgNew = ImageCreateTrueColor($width,$height);    //requires GD 2.0
  ImageCopyResampled($imgNew,$imgOld,0,0,0,0,$width,$height,imagesx($imgOld),imagesy($imgOld));    //requires GD 2.0
  ImageJpeg($imgNew,$uploaded_pic);
  Imagedestroy($imgNew);
  }
}



Anybody know how make this code work with 1.3 version?

groan

i was just going to ask...not working...!!!! :-\\

ytknows

hate to bump this old thread, but if anyone could modify this to work with 1.3.x, that'd be great.

Cisi

I agree , would be very nice to make working with 1-3-x .. very useful .
;)

sweeet

Yeah please make this Hack available for 1.3.x
Anyone without unlimited traffic will thank you ;)

kegobeer

Resizing during the upload process has been incorportated into 1.4, but will not be reverse engineered for 1.3.x.
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots