www.onebee.com

Web standards alert

Account: log in (or sign up)
onebee Writing Photos Reviews About

Making speedy deliveries day by day—12:08 PM

All right, kiddies! Say you have an object that represents a photo gallery image and you want to make sure that it displays at the proper size. (If it's a slide, it should be no more than 90 pixels along its longest side, or no more than 68px along its shortest – whichever is smaller; otherwise, it just needs to be 500px or narrower, regardless of the height.) How would you come up with the proper width and height attributes? Eh, hotshot?!

Well, here's how I did it:

switch($this->type){
case "slide":
$maxwidth = ($this->isVertical())? 68: 90;
$maxheight = ($this->isVertical())? 90: 68;
break;
default:
$maxwidth = 500;
$maxheight = $this->height;
break;
}
if($this->width > $maxwidth){
$widthratio = $maxwidth/$this->width;
}
if($this->height > $maxheight){
$heightratio = $maxheight/$this->height;
}
if($widthratio && $heightratio){
if($widthratio > $heightratio){
unset($widthratio);
} else {
unset($heightratio);
}
}
if($widthratio){
$height = number_format($this->height * $widthratio);
$width = $maxwidth;
} else if($heightratio){
$width = number_format($this->width * $heightratio);
$height = $maxheight;
} else {
$width = $this->width;
$height = $this->height;
}

Can you beat that shit? Woo!

Not that this is the most spectacularly impressive part of this week's work, which has resulted in photos and galleries working on the front end. (Yay!) But it looks nice and geeky, which is exactly the point. This is a process laden with geeky minutiae. And there's a light at the end of the tunnel, people.

Photos! Galleries! Working! Weeeeeee!

(In related news, I have discovered that I'm physically incapable of watching The Amazing Race without my McRace peeps. I don't know what I'm going to do. I've never known myself to be so desperate for an audience for my wisecracks. Maybe I should make a podcast of my sarcastic commentary...)

Your Comments
Name: OR Log in / Register to comment
e-mail:

Comments: (show/hide formatting tips)

send me e-mail when new comments are posted

onebee
POLL:
alt.web.nerdery

The geeky stuff?

Enough already!
Bring it on! I love it!
Eh, I can always skim past it.

 (0 comments)