Image sizing options

Kevin Somervill <[email protected]> Sun, 03 Nov 2002 23:38:27 -0800
Newsgroups gmane.comp.web.cthumb.devel,gmane.comp.web.cthumb.general
Message-ID <[email protected]>
Hi folks,
I've been using cthumb for almost a year now and think its the best free
album maker available for linux (or windoze for that matter).  My
dilemma was that I like to take picture with my digital camera with the
pictures as large as it will let me.  This resulted in pictures larger
than the screen resolution of many of my viewers (i.e. the grandparents
of my children). I added two options, -X and -Y, to allow me to specify
the maximum image size rendered by the browser without having to save
off modified pictures.  The patch accepts the commandline options,
cthumbrc options, or album options.  In either of the album or the rc,
the variables added are as follows:

# maximum image width
MaxImageWidth: 800

# maximum image height
MaxImageHeight: 600

If these are commented out or set to 0, the image will be displayed at
full resolution.  The commandline options take precedence over the rc or
album files and the default is 0 for both (for full size).  I tried the
cvs -cN and got nothing useful (probably was not using it correctly). 
The attached file is from a 

  $ diff cthumb my_patched_cthumb > ks_11_3_2002.diff

I originally wrote this for the 4.1 revision, but when you released the
4.2 rev I decided I had better send in my stuff befoe you guys got to
rev 5.0.  The diff is from the recently released 4.2 revision. Hope this
is acceptable. Let me know what you think.

Thanks,
ks
-- 
Kevin Somervill                        e-mail: [email protected]

"We all know Linux is great...it does infinite loops in 5 seconds."
(Linus Torvalds about the superiority of Linux on the Amterdam
Linux Symposium)
ks_11_3_2002.diff (text/plain, 3.3 KB)
31c31
< my $version = "4.2";
---
> my $version = "4.2 - Kevin's patch";
33a34
>   
58a60,70
> 
> 	# KS:ADDED
> 	# MaxImageWidth and MaxImageHeight are to be used to limit the size of
>         # of the image in the slide.  This is so you can keep pages from being
>         # generated that will have pictures larger than the screen. Is there a 
> 	# way to do this dynamically at the client?  Maybe embed some jscript
>         # to handle image size with respect to the screen size.
> 	["MaxImageWidth"              , "integer", "X", "0"               , " ", " ", "c", "maximum image width"],
> 	["MaxImageHeight"             , "integer", "Y", "0"               , " ", " ", "c", "maximum image height"],
>         # END KS:ADDITION	
>        
89c101
< 	["RecursiveCP"                , "string" , "" , "cp -r"           , " ", "x", "x", "'cp -a' for gnu cp, set to 'cp -r' for bsd, else 'rsync -avq'"],
---
> 	["RecursiveCP"                , "string" , "" , "rsync -avqC"           , " ", "x", "x", "'cp -a' for gnu cp, set to 'cp -r' for bsd, else 'rsync -avq'"],
112a125,130
> 
> # KS: ADDED 05.12
> my $MaxImageWidth = 0;
> my $MaxImageHeight = 0;
> # END KS:ADDITION	
> 
187c205
<     &getopt('Hlfxyis', \%opt);
---
>     &getopt('HlfXYxyis', \%opt);
214a233,234
> 	print "\t-X <n>: Displayed image width\n";
> 	print "\t-Y <n>: Dislpayed image height\n";
282a303,320
>     
> 
>     # KS: ADDED 5.12
>     if ($opt{X}) {	# maximum image width
> 	my $x = int ($opt{X});
> 	if ($x > 2) {
> 	    $MaxImageWidth = $x;
> 	}
>     }
> 
>     if ($opt{Y}) {	# maximum image height
> 	my $y = int ($opt{Y});
> 	if ($y > 2) {
> 	    $MaxImageHeight = $y;
> 	}
>     }
>     # END KS:ADDITION	
> 
1218,1219d1255
<     $str .= "width=\"@$pictureGeometry[0]\" ";
<     $str .= "height=\"@$pictureGeometry[1]\" ";
1220a1257,1289
>     # KS: Force image scaling here?
>     #
>     # Set the width and height html tags per the Max values if given.
>     my $xDimension = @$pictureGeometry[0];
>     my $yDimension = @$pictureGeometry[1];
> 
>     if ( ( ($MaxImageWidth > 0) || ($MaxImageHeight > 0) ) &&  
> 	 ( (@$pictureGeometry[0] > $MaxImageWidth) ||
> 	   (@$pictureGeometry[1] > $MaxImageHeight) ) ) {
>       
>       
>       if ( ($MaxImageWidth > 0) && ($xDimension > $MaxImageWidth) ) {
> 	# The width is the limiting dimension.  Adjust accordingly.
> 	$yDimension = int ( $yDimension / $xDimension * $MaxImageWidth );
> 	$xDimension = $MaxImageWidth;
>       }
>       
>       if ( ($MaxImageHeight > 0) && ($yDimension > $MaxImageHeight) ) {
> 	# The height is the limiting dimension.
> 	$xDimension = int ( $xDimension / $yDimension * $MaxImageHeight );
> 	$yDimension = $MaxImageHeight;
>       }
>     }
>     $str .= "width=\"$xDimension\" ";
>     $str .= "height=\"$yDimension\" ";
>     #}
>     #else {
>     #  $str .= "width=\"@$pictureGeometry[0]\" ";
>     #  $str .= "height=\"@$pictureGeometry[1]\" ";
>     #}
>     # END KS:ADDITION	
> 
>     
1226c1295,1300
<         $str .= ", " . @$pictureGeometry[0] . "x" . @$pictureGeometry[1];
---
>       # KS: Need to set the value here if the image size was limited with 
>       # either of MaxImageWidth or MaxImageHeight
>       # Do we show the images displayed size or the images actual size?
>         #$str .= ", " . @$pictureGeometry[0] . "x" . @$pictureGeometry[1];
>         $str .= ", " . $xDimension . "x" . $yDimension;
>       # END KS:ADDITION