[KNOWN ISSUE] Please remove "(px)" from Width and Height in module "Random Image"

Locked
dev-zero
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Jun 22, 2006 1:14 pm

[KNOWN ISSUE] Please remove "(px)" from Width and Height in module "Random Image"

Post by dev-zero » Thu Jun 22, 2006 1:23 pm

Hi

Well it's a tiny thing, but it is there since Mambo: On the left of "Width" and "Height" in module "Random Image" it says "(px)", which is not true. It is possible to use any size specification allowed.
In our case, we have a folder with images of different size and don't want them to be resized, so I used "100%" for width and height. This way we don't have to patch the module-file after every update  :P

Thanks & greets

User avatar
toubkal
Joomla! Hero
Joomla! Hero
Posts: 2860
Joined: Thu Aug 18, 2005 4:35 pm
Location: Cheshire, England
Contact:

Re: Please remove "(px)" from Width and Height in module "Random Image"

Post by toubkal » Thu Jun 22, 2006 2:09 pm

Looking at the code, it should be px because IF you only specify 1 dimension e.g. width (which is very useful if you wish a range of differently proportioned images to fit within a fixed width) the code will calaculate the other dimension to maintain the correct aspect:

Code: Select all

	  	$size 			= getimagesize ($abspath_image);

	  	if ($width == '') {
	  		($size[0] > 100 ? $width = 100 : $width = $size[0]);
	  	}
	  	if ($height == '') {
	  		$coeff 	= $size[0]/$size[1];
	  		$height = (int) ($width/$coeff);
	  	}
this is done using getimagesize() function which returns values in px (although the issue is really that the width you supply gets divided by the coeff, which is not going to work correctly if you have supplied anything other than a plain number )

if you specify both dimensions, then the dimensions just get used in the img html width and height so in that case it does not matter.

I suppose you could explain this in the module, but it may confuse as many people as it helps
Last edited by toubkal on Thu Jun 22, 2006 2:45 pm, edited 1 time in total.
Do you want the answer to be as vague as your question?

dev-zero
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Jun 22, 2006 1:14 pm

Re: Please remove "(px)" from Width and Height in module "Random Image"

Post by dev-zero » Thu Jun 22, 2006 3:02 pm

Well, it auto-calculates only the height, so I would propose the following:

Code: Select all

                 if ($width == '') {
                         if ($height == '') {
                                 $coeff        = $size[0]/$size[1];
                                 $width = (int) ($height*$coeff);
                         else {
                                 ($size[0] > 100 ? $width = 100 : $width = $size[0]);
                         }
                 }
                 if ($height == '') {
                         $coeff        = $size[0]/$size[1];
                         $height = (int) ($width/$coeff);
                 }
But the real problem is this: There's no note about a default value if the fields are left empty. So my assumption (and probably that of many users) was that if I don't specify anything, it doesn't resize anything. If the pictures are resized to a hardcoded value, it has to be at least documented. But anyway, hardcoding magic numbers is bad coding style.


So I would change code to:

Code: Select all

                 if ($width == '') {
                         $width = $size[0];
                         if ($height != '') {
                                 $coeff        = $size[0]/$size[1];
                                 $width = (int) ($height*$coeff);
                         }
                }
                 if ($height == '') {
                         $coeff        = $size[0]/$size[1];
                         $height = (int) ($width/$coeff);
                 }
... and than add a note like: "You can also specify the size in percent but make sure you specify both width and height"
This way you probably have 99 percent of all use cases covered.

A much nicer implementation would be to use/code a generic image-manipulation/parameters-component which could be used everywhere you can include an image.

User avatar
toubkal
Joomla! Hero
Joomla! Hero
Posts: 2860
Joined: Thu Aug 18, 2005 4:35 pm
Location: Cheshire, England
Contact:

Re: Please remove "(px)" from Width and Height in module "Random Image"

Post by toubkal » Thu Jun 22, 2006 3:21 pm

Code: Select all

if ($width == '') {
	  		($size[0] > 100 ? $width = 100 : $width = $size[0]);
if no width supplied it checks if the image is greater than 100px and if so it sets the width to 100 otherwise width is actual width
Do you want the answer to be as vague as your question?

dev-zero
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Thu Jun 22, 2006 1:14 pm

Re: Please remove "(px)" from Width and Height in module "Random Image"

Post by dev-zero » Thu Jun 22, 2006 6:31 pm

Well, that's exactly the thing I think it shouldn't do. I mean, what sense does it make?

User avatar
RobS
Joomla! Ace
Joomla! Ace
Posts: 1367
Joined: Mon Dec 05, 2005 10:17 am
Location: New Orleans, LA, USA
Contact:

Re: Please remove "(px)" from Width and Height in module "Random Image"

Post by RobS » Thu Oct 26, 2006 7:51 am

Moving to known issues.  This is a feature request and will not be addressed in the 1.0.x branch. 
Rob Schley - Open Source Matters
Webimagery - http://www.webimagery.net/ - Professional Consulting Services
JXtended - http://www.jxtended.com/ - Free and Commercial Joomla! Extensions


Locked

Return to “Known Issues - Archive”