dc_jt Posted August 4, 2008 Share Posted August 4, 2008 Hi Im having a lot of trouble trying to work out what sizes to re-size my images to. Basically I re-size my images on the fly, however they go into a gallery which has a frame of 628w x 432h. Now, what I'm struggling with is working out how best to fit each image into this frame. This is what I have so far but its still not correct: //loop through gallery <?php while ($aActualImage = mysql_fetch_array($rGallery)) { //if landscape image if ($aActualImage['image_width'] > $aActualImage['image_height']){ // get width for template 9005 (628) $aSetlarge = _grabImageSize('9005',$aActualImage['image_width'],$aActualImage['image_height']); //if max width is greater than the actual image width if($aSetlarge['width'] > $aActualImage['image_width']){ $aSetlarge['width'] = $aActualImage['image_width']; $aSetlarge['height'] = $aActualImage['image_height']; } else { $aSetlarge['width'] = $aSetlarge['width']; $aSetlarge['height'] = $aSetlarge['height']; } //else if portrait image } elseif ($aActualImage['image_height'] > $aActualImage['image_width']){ get width for template 9006 (432) $aSetlarge = _grabImageSize('9006',$aActualImage['image_width'],$aActualImage['image_height']); //if max height is greater than actual image height if($aSetlarge['height'] > $aActualImage['image_height']){ $aSetlarge['height'] = $aActualImage['image_height']; $aSetlarge['width'] = $aActualImage['image_width']; } else { $aSetlarge['height'] = $aSetlarge['height']; $aSetlarge['width'] = $aSetlarge['width']; } //else if square } else { $aSetlarge = _grabImageSize('9004',$aActualImage['image_width'],$aActualImage['image_height']); if($aActualImage['image_height'] > $aSetlarge['height']){ $aSetlarge['height'] = $aSetlarge['height']; $aSetlarge['width'] = $aSetlarge['width']; } else { $aSetlarge['width'] = $aActualImage['image_width']; $aSetlarge['height'] = $aSetlarge['height']; } } $sSizelarge = $aSetlarge['width'].'x'.$aSetlarge['height']; //Set image size Can anyone see what Im missing? Most images seem fine, although on some, the height is too big for the frame. Once I have realised it is a landscape, portrait or square would I then find out if the actual image width is greater than the frame width and also check if the actual image height is greater than the frame height? Im so confused now!! Anyhelp would be greatly appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/118063-image-re-sizing/ Share on other sites More sharing options...
ignace Posted August 4, 2008 Share Posted August 4, 2008 http://mediumexposure.com/techblog/smart-image-resizing-while-preserving-transparency-php-and-gd-library Quote Link to comment https://forums.phpfreaks.com/topic/118063-image-re-sizing/#findComment-607486 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.