forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Watermarking & image manipulation => Topic started by: mrob on May 24, 2004, 04:22:20 am

Title: Resize on upload
Post by: mrob on May 24, 2004, 04:22:20 am
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
Title: Re: Resize
Post by: RatKing on May 24, 2004, 09:57:39 am
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.
Title: Re: Resize
Post by: mrob on May 24, 2004, 01:28:57 pm
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.
Title: Re: Resize
Post by: RatKing on May 26, 2004, 12:59:12 pm
I'll see what I can do for you over the weekend, should not be to hard to build a little hack for this. :)
Title: Re: Resize
Post by: RatKing on May 26, 2004, 10:03:20 pm
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)

Code: [Select]
                } 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
Code: [Select]
} 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
Code: [Select]
                } 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
Code: [Select]
} 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)
Title: Re: Resize
Post by: mrob on May 27, 2004, 10:41:15 am
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.
Title: Re: Resize
Post by: Joachim Müller on May 30, 2004, 09:25:33 pm
I 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
Title: Re: Resize
Post by: cuteseal on August 12, 2004, 05:14:05 am
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
Title: Re: [CPG1.3.x]: Resize
Post by: cuteseal on August 12, 2004, 08:16:52 am
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
Title: Re: [CPG1.3.x]: Resize
Post by: lvanderb on August 23, 2004, 02:08:58 am
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
Title: Re: Resize on upload
Post by: seros on September 26, 2004, 06:43:10 pm
Does it work with this MOD? http://forum.coppermine-gallery.net/index.php?topic=9578.msg42951#msg42951
Title: Re: Resize on upload
Post by: Joachim Müller on September 26, 2004, 08:47:29 pm
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
Title: Re: Resize on upload
Post by: seros on September 30, 2004, 05:47:19 pm
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 ...
Title: Re: Resize on upload
Post by: Medar on October 12, 2004, 04:32:22 am
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.
Title: Re: Resize on upload
Post by: Medar on October 12, 2004, 04:47:59 am
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?
Title: Re: Resize on upload
Post by: 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.
Title: Re: Resize on upload
Post by: kegobeer on December 17, 2004, 01:31:40 am
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.
Title: Re: Resize on upload
Post by: Tranz on December 17, 2004, 01:44:37 am
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.
Title: Re: Resize on upload
Post by: SimmDogg on December 17, 2004, 01:56:03 am
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 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.
Title: Re: Resize on upload
Post by: SimmDogg on December 17, 2004, 01:59:56 am
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?
Title: Re: Resize on upload
Post by: Joachim Müller on December 17, 2004, 07:32:19 am
http://prdownloads.sourceforge.net/coppermine/cpg1.3.0_mod_limit_files.zip?download (zip)
or
http://prdownloads.sourceforge.net/coppermine/cpg1.3.0_mod_limit_files.tar?download (tar)

Joachim
Title: Re: Resize on upload
Post by: SimmDogg on December 18, 2004, 06:26:53 am
That's the download I am using but it doesn't work for me. Does it matter what the gallery directory is called? What could be the problem? Any ideas?
Title: Re: Resize on upload
Post by: SimmDogg on February 13, 2005, 05:34:51 pm
Can I get a little help with this Resize on upload mod? I have tried to edit existing files as shown and instructed in these forums and I have installed the cpg1.3.0_mod_limit_files.zip. Neither has worked. Any help would appreciated.
Title: Re: Resize on upload
Post by: stranho on July 22, 2006, 04:11:43 pm
Precise of a Hack for version 1.4x that redimensione the images in the upload and if possible it lowers the quality of the image 
 
Thanks
Title: Re: Resize on upload
Post by: Joachim Müller on July 22, 2006, 10:22:18 pm
Don't ask for other versions (http://forum.coppermine-gallery.net/index.php?topic=24540.0)