Resize on upload Resize 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 on upload

Started by mrob, May 24, 2004, 04:22:20 AM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

mrob

I'd like to limit the size of uploaded files, but not reject those that are too large.  Instead, I'd like to have the image resized if it's too large.  In effect, I'd like to just have the thumbnail and intermediate files, but not the original.  Is this possible?

Thanks,
Mike

RatKing

That should be posible but for one slight problem... Files are usualy limted to 1024Kb upload to prevent DoS atacs on servers and so on. Other than that a long upload might result in a timeout of the webbrowser again a problem.

If all the problems above are not an issue and you are not worried about all the security problems that the upload of big files brings with it, it should be quite easy to create this fix for this. Personlay I would say don't just srink the image on your computer before upload or upload the via FTP.

mrob

Thanks for the reply.  I wouldn't have a problem with having a file rejected on file size.  But for those that are accepted, I would like to have resized based on the maximum image dimension.

RatKing

I'll see what I can do for you over the weekend, should not be to hard to build a little hack for this. :)

RatKing

Ok, I don;t have a life I know but the solution to this problem I do have...

The upload.php file needs a little change to get this working.

The following two parts need to be corrected (this is CPG1.3)

                } elseif (max($imginfo[0], $imginfo[1]) > $CONFIG['max_upl_width_height']) {
                    @unlink($path_to_image);

                    // The file upload has failed -- the image dimensions exceed the allowed amount.
                    $file_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'file_name'=> $file_name, 'error_code'
=>$lang_upload_php['pixel_allowance']);

                    // There is no need for further tests or action, so skip the remainder of the iteration.
                    continue;
                }
with} elseif (max($imginfo[0], $imginfo[1]) > $CONFIG['max_upl_width_height']) {
// RatKing's hack to resize images that are 'to big' according to the admin
  // Determain which is the tallest width or height.
  if ( $imginfo[0] > $imginfo[1] ) { $tall = 'wd'; } else { $tall = 'ht'; }

  // Simply resize the image to the biggest file size that is allowed.
  resize_image($path_to_image, $path_to_image, $CONFIG['max_upl_width_height'], $CONFIG['thumb_method'], $tall);

  // Should be all there is to it Now when I upload a very big file it will be squashed
  // nothing more to do we can just escape this if loop and process the image
  continue;
}

and
                } elseif (max($imginfo[0], $imginfo[1]) > $CONFIG['max_upl_width_height']) {
                    @unlink($path_to_image);

                    // The file upload has failed -- the image dimensions exceed the allowed amount.
                    $URI_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'URI_name'=> $_POST['URI_array'][$count
er], 'error_code'=>$lang_upload_php['pixel_allowance']);

                    // There is no need for further tests or action, so skip the remainder of the iteration.
                    continue;
                }
with} elseif (max($imginfo[0], $imginfo[1]) > $CONFIG['max_upl_width_height']) {
// RatKing's hack to resize images that are 'to big' according to the admin
  // Determain which is the tallest width or height.
  if ( $imginfo[0] > $imginfo[1] ) { $tall = 'wd'; } else { $tall = 'ht'; }

  // Simply resize the image to the biggest file size that is allowed.
  resize_image($path_to_image, $path_to_image, $CONFIG['max_upl_width_height'], $CONFIG['thumb_method'], $tall);

  // Should be all there is to it Now when I upload a very big file it will be squashed
  // nothing more to do we can just escape this if loop and process the image
  continue;
}
}


In my "development/mess about" version of CPG1.3 I have also made a change to the config page and the english language file so I can enable and disable this function on the config page.

I have not posted that code here but if you want I could send the modified files to you. np...

I am not sure if this will work in CPG1.2 I think it will but I have not tested this yet (to little time to test that for now)

mrob

Wow, thanks for the quick effort!  I'll give it a try when I get a chance.  No need to send me the other changes...I would always keep this feature enabled.  I'll let you know how it goes.

Joachim Müller

Quote from: RatKing on May 26, 2004, 10:03:20 PMI have not posted that code here but if you want I could send the modified files to you. np...
I would like to have a look, could you post your "full hack" for cpg1.3.0?

Thanks

GauGau

cuteseal

Hi,

Nice mod/hack!  It wasn't working for me (i'm using 1.3.1) but noticed that if you comment out the "continue;" statements, then it works like a charm!!

I think there's some code at the end of each iteration to add successful files to an array.  The continue statements were skipping those.

Cheers,
Julian

cuteseal

Ooh, I just noticed that on resized images, the EXIF data is lost! :(

If I resize beforehand and upload, then the data is retained.


Any ideas how this can be fixed?

Thanks,
Jules

lvanderb

Hi,

I just posted a hack on how to resize originals, after which, of course, I found RatKing's mod!  

Then I also noticed that my EXIF info was being lost too... at any rate, I figured out how to save it when resizing originals and it's posted with my resize original hack, at the bottom...

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

Linda


Joachim Müller

why don't you find this out for us ::)? How are we to know? All we can do is try this as well. Just backup your files, so you can savely go back.

Joachim

seros

So i have tried and and replaced the "$CONFIG['max_upl_width_height']" with "$USER_DATA['group_max_upl_width_height']" but it doesn't work yet I'm trying ...

Medar

This would be incredible to have as an option in the Config.   Why you say?   Those people who have potentially limited webspace (or bandwidth), but have 6 megapixel cameras taking 1.2 meg images!

Working to add it right now.  Getting the "Error Message - Exceeded filesize permitted by CPG." right now, so trying to figure out why it is giving me this after the hack.

Medar

Yep, I cannot get past the error.  I have the code correct (I did not comment out the CONTINUE statement like cuteseal did, I tried and it still did nothing).

I am using CPG1.32 - this should work in 1.32, correct?

SimmDogg

Why doesn't someone post the corrected files. I have made some changes to the files referenced but nothing is working. I think this is part to too many people trying to put their 2 cents in. If you know what you are doing, post the files somewhere so we can download them. Referencing line #'s and yada yada don't work. Just post the files.

kegobeer

The devel version has resizing during uploads.  You'll have to wait for 1.4 to be released to see it, since I'm the one who did the coding for the devel version and I'm not reverse engineering the code to work with a soon-to-be outdated version.
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

Tranz

Quote from: SimmDogg on December 16, 2004, 10:58:02 PM
Why doesn't someone post the corrected files. I have made some changes to the files referenced but nothing is working. I think this is part to too many people trying to put their 2 cents in. If you know what you are doing, post the files somewhere so we can download them. Referencing line #'s and yada yada don't work. Just post the files.
Someone already put in the time and effort to come up with the mod and to post it. If you're too lazy to apply the changes yourself, don't use it. Maybe the person was using a modded file. There's no point in you using their already modified modded file.

SimmDogg

#18
QuoteSomeone already put in the time and effort to come up with the mod and to post it. If you're too lazy to apply the changes yourself, don't use it. Maybe the person was using a modded file. There's no point in you using their already modified modded file.

I have already tried using the modded files. I have tried to apply the changes to the original dev files. Nothing has worked. I'm not lazy. I 've worked with these changes about 6-10 times and none of what I have tried(from post to this board) have worked.

SimmDogg

#19
Quote
Someone already put in the time and effort to come up with the mod and to post it. If you're too lazy to apply the changes yourself, don't use it. Maybe the person was using a modded file. There's no point in you using their already modified modded file.


I have tried using this download and I am still getting errors.

"cpg1.3.0_mod_limit_files.zip"

Is this the correct download?