Jump to content

Image Re-Sizing


dc_jt

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/118063-image-re-sizing/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.