Resize Large Coppermine Images on Upload

Dragonfly issues as they relate to modules discussed here
  
22 Jan '11 Sat Jan 22, 2011 17:53    
layingback
Site Admin  
  •  

Envio Resize Large Coppermine Images on Upload

NOTE THAT THIS IS BETA CODE - REQUIRES TESTING BEFORE PRODUCTION USE

If you are like me you want to limit the maximum size of uploaded Coppermine images. 12MB images are just too big to display meaningfully.

But like me you have members who couldn't resize an image successfully if a valuable prize was offered!

So I've developed this simple patch to resize images on the fly during user upload in Coppermine. It is developed as an extension to the Max Image Dimension option in Pro_News. But it is not difficult to configure it to work without Pro_News - if you haven't yet been turned on to the benefits of Pro_News as THE module in your DragonflyCSM website. Guiño

As noted on DragonflyCMS.org if you are running DF 9.2.1 (vs some later release) then you must change line 34 of /includes/imaging/gd2.inc to:

PHP:
	if (CAN_MOD_INI) ini_set('memory_limit', '128M');

(128MB is most likely needed here, because we are dealing with larger target images sizes when resizing the original image.)

In /includes/coppermine/picmgmt.inc find on line 26:

PHP:
	global $db, $CONFIG, $ERROR, $USER_DATA, $PIC_NEED_APPROVAL, $CPG_M_DIR;


and replace with:

PHP:
	global $db, $CONFIG, $ERROR, $USER_DATA, $PIC_NEED_APPROVAL, $CPG_M_DIR, $MAIN_CFG;



In /includes/coppermine/picmgmt.inc find on line 43:

PHP:
	if (max($imginfo[0], $imginfo[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'] && !file_exists($normal) &&


and replace with: UPDATE - Improved version for this part below

PHP:
	if (max($imginfo[0], $imginfo[1]) > $MAIN_CFG['pro_news']['img_limit'] &&
!resize_image($src_file, $imginfo, $image, $MAIN_CFG['pro_news']['img_limit'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], $watermark)) {
unlink($thumb);
return false;
}

if (max($imginfo[0], $imginfo[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'] && !file_exists($normal) &&



If you use Pro_News this will resize the original image to comply with the Max Image Dimension in Config. If you do not have Pro_News installed, then you will need to go into phpMyAdmin, select the cms_config_custom file, and insert the following record:

Code:
	cfg_name		pro_news
	cfg_field		img_limit
	cfg_value		800


where 800 can be any value, and represents the maximum height or width for an upload image before resizing kicks in. And after updating you will need to delete the config_MAIN_CFG.php file in your /cache folder for the update to take effect.

This should be sufficient, at least it works for me on 9.2.1.

I would be interested in hearing any feedback. Or appreciation. Guiño



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 


Ultima edición por layingback el Thu Aug 04, 2011 15:09, editado 2 veces 
 
 
  
23 Jan '11 Sun Jan 23, 2011 15:02    
rosbif
BetaTester  BetaTester
  •  

Envio Re: Resize Large Coppermine Images on Upload

Just tried this. Tried to upload an image that is 2.11Mb and got a scrambled page after a couple of minutes wait with a message near the bottom of:

CMS Error /home/chantill/public_html/modules/coppermine/db_input.php line 360:
The size of the file you have uploaded is too large (maximum allowed is 2097152 KB) !


PHPinfo shows Memory_Limit as 32M which I guess comes from my php.ini file? It also shows upload_max_filesize as 10M and post_max_size as 55M.

The resize code in /includes/coppermine/picmgmt.inc looks like this. Is that right?

PHP:
	if (max($imginfo[0], $imginfo[1]) > $MAIN_CFG['pro_news']['img_limit'] &&
!resize_image($src_file, $imginfo, $image, $MAIN_CFG['pro_news']['img_limit'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], $watermark)) {
unlink($thumb);
return false;
}
if (max($imginfo[0], $imginfo[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'] && !file_exists($normal) &&
!resize_image($src_file, $imginfo, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], $watermark)) {
unlink($thumb);
return false;
}



rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

Linux/2.2.11/4.1.22/5.2.17/9.3.4.1

 
 
 
 
  
23 Jan '11 Sun Jan 23, 2011 15:42    
layingback
Site Admin  
  •  

Envio Re: Resize Large Coppermine Images on Upload

My patch does nothing for the php limit on 2MB uploads. Try with large (width, height) image which is not > 2MB.

Nano's post here purports to address this 2MB limit, but your settings already seem larger than his suggested changes, so ...



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
  
23 Jan '11 Sun Jan 23, 2011 15:54    
rosbif
BetaTester  BetaTester
  •  

Envio Re: Resize Large Coppermine Images on Upload

Hmm, odd. Not sure where the 2M figure is still coming from. I've not had a problem with larger images before...



rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

Linux/2.2.11/4.1.22/5.2.17/9.3.4.1

 
 
 
 
  
23 Jan '11 Sun Jan 23, 2011 17:30    
layingback
Site Admin  
  •  

Envio Re: Resize Large Coppermine Images on Upload

What's your Max size for uploaded pictures (KB) in Coppermine > Config? 2048KB?



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
  
23 Jan '11 Sun Jan 23, 2011 17:48    
rosbif
BetaTester  BetaTester
  •  

Envio Re: Resize Large Coppermine Images on Upload

That was a rhetorical question wasn't it? Guiño

So that allowed me to upload it (took over a minute) - however it has set the max dimension to 2048 despite the fact that in PN the max dimension is set to 800 (it's 2048 in coppermine).



rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

Linux/2.2.11/4.1.22/5.2.17/9.3.4.1

 
 
 
 
  
23 Jan '11 Sun Jan 23, 2011 17:57    
layingback
Site Admin  
  •  

Envio Re: Resize Large Coppermine Images on Upload

- rosbif

So that allowed me to upload it (took over a minute)


Never said that uploading the large version was ever a good idea Sonriente

The code segment you pasted above looks right. You did include the $MAIN_CONFIG in global edit as well I trust? Because if it doesn't find PN entry it will default to CPG one (been there, done that!)



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
  
23 Jan '11 Sun Jan 23, 2011 18:02    
rosbif
BetaTester  BetaTester
  •  

Envio Re: Resize Large Coppermine Images on Upload

It's there

global $db, $CONFIG, $ERROR, $USER_DATA, $PIC_NEED_APPROVAL, $CPG_M_DIR, $MAIN_CFG;



rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

Linux/2.2.11/4.1.22/5.2.17/9.3.4.1

 
 
 
 
  
23 Jan '11 Sun Jan 23, 2011 18:29    
layingback
Site Admin  
  •  

Envio Re: Resize Large Coppermine Images on Upload

Not sure what is up then.

What size image (in px) did you start out with?

I've revised the code slightly, but this doesn’t affect the basic logic, just ensures that the intermediate/normal image is generated from the same original, not from the resized one (double jeopardy for image quality).

PHP:
	if (max($imginfo[0], $imginfo[1]) > $CONFIG['picture_width'] && $CONFIG['make_intermediate'] && !file_exists($normal) &&
!resize_image($src_file, $imginfo, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], $watermark)) {
unlink($thumb);
return false;
}

if (max($imginfo[0], $imginfo[1]) > $MAIN_CFG['pro_news']['img_limit'] &&
!resize_image($src_file, $imginfo, $image, $MAIN_CFG['pro_news']['img_limit'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], $watermark)) {
unlink($normal);
unlink($thumb);
return false;
}



I'm doing this on 9.2.1, specifically version 9.14 of picmgmt.inc



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
  
23 Jan '11 Sun Jan 23, 2011 19:27    
rosbif
BetaTester  BetaTester
  •  

Envio Re: Resize Large Coppermine Images on Upload

Same versions here. Have just tried again and it's resized it to 1090 x 800...



rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

Linux/2.2.11/4.1.22/5.2.17/9.3.4.1

 
 
 
 
  
23 Jan '11 Sun Jan 23, 2011 21:49    
layingback
Site Admin  
  •  

Envio Re: Resize Large Coppermine Images on Upload

OK, assuming it was bigger originally, it's resized based on the smallest side ...

Don’t understand why it does this for you and enginama, when every image that I've done has adjusted based on the long side. (With both versions of the code. And I've tested with 11 unique images.)



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
  
23 Jan '11 Sun Jan 23, 2011 22:01    
layingback
Site Admin  
  •  

Envio Re: Resize Large Coppermine Images on Upload

Oh, oh, oh! What have you set 'Use dimension ( width or height or Max aspect for thumbnail )*' in CPG Config?

I have mine set to Max aspect, so it is checking both and resizing to the largest. I'm guessing you guys have it set to width (or height) and so it only handles that 1 case.

Can you try with Max aspect please? Just so we know...

I'm not sure it is possible to handle the other 2 cases easily, but I will take a look. Although I do think Max aspect is the way to go as an Admin Guiño



layingback's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

2.6.32 / 1.3 - 2.4 / 5.5 - 5.6 / 5.4 - 5.5 / 9.4

 
 
 
 
  
24 Jan '11 Mon Jan 24, 2011 12:35    
rosbif
BetaTester  BetaTester
  •  

Envio Re: Resize Large Coppermine Images on Upload

Looks to be working perfectly... It resized a large image to 800 x 600 (and seemed quicker on a bigger image too?).

So did the original upload not do this anyway from looking at the code?



rosbif's server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS)

Linux/2.2.11/4.1.22/5.2.17/9.3.4.1

 
 
 
 
Link  QR 
Share this Versión Imprimible  facebook   google+   linkedin   twitthis  
Show more ...



Control de Permisos a los Foros - Puede publicar nuevos temas en este foro
No puede responder a temas en este foro
No puede editar sus mensajes en este foro
No puede borrar sus mensajes en este foro
No puede votar en encuestas en este foro
You cannot attach files in this forum
Tu puedes descargar archivos en este foro