Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

57 users online



PHP/ image size resolution dependant.

PHP/ image size resolution dependant.

Currently viewing this thread: 1 (0 members and 1 guests)


tcbil

tcbil

I hate Customer Services!
Status: Offline!

PHP/ image size resolution dependant.

I have a tring ($resolution) that returns the user's resolution and I would like to use that to set a width for my pictures but am not quite sure how? Basically my work resolution is 1280x960 (this is the returned format) so when i check my gallery from work the pictures should appear at 800px wide for example, is ther any easy way to do this in PHP?

Thanks in advance

___________________

PHP Freak Wannabe!

howdy

howdy

Neverside Newbie
Status: Offline!
PHP:

<?php 
$resolution 
'1280x960';
$width '800';  // default
$height '600';  // default

$pos strpos($resolution'x');
if (
$pos === false) {
  echo 
"error invalid resolution";
} else {
  
$width substr($resolution0$pos) . "px";
  
$height substr($resolution$pos+1strlen($resolution)) . "px";
}

echo 
"<img src=\"gallery-rotate2.gif\" style=\"width: $width; height: $height;\"/>";

?>

___________________

Haudenschilt.com

tcbil

tcbil

I hate Customer Services!
Status: Offline!

sorry to be a bit slow but would you be able to explain what the code does and how it works?

Thanks

___________________

PHP Freak Wannabe!

howdy

howdy

Neverside Newbie
Status: Offline!
PHP:

<?php 
// this is just an exampleyou said your script already assigns this for you
$resolution '1280x960'
$width '800';  // default value
$height '600';  // default value

// find the position of the x in 1280x960
$pos strpos($resolution'x');

// if $pos is false it means their was no x in the $resolution string, so we output an error
if ($pos === false) {
  echo 
"error invalid resolution";

// otherwise $pos should be the position of the x
} else {

  
// split the $resolution string into two parts
  // first part of the string is from the beggining, 0 all the way to the x we found earlier, which is position $pos
  // we add a px to the end of the new substring and call it $width
  
$width substr($resolution0$pos) . "px";

  
// same thing as with width but in this case we start at $pos + 1 cause we don't want to include the x
  // and end at the length of the string
  
$height substr($resolution$pos+1strlen($resolution)) . "px";
}

// just echo out the image with the new width and height
// output will look something like
// <img src="yourimage.gif" style="width: 1280px; height: 960px;" />
echo "<img src=\"yourimage.gif\" style=\"width: $width; height: $height;\"/>";

?>

___________________

Haudenschilt.com

tcbil

tcbil

I hate Customer Services!
Status: Offline!

Ok that is getting close to what i need, the only prblem is now i need to reduce the size of the images, for example if the resolution was 1280x960 then the widh of the image would need to be about 800px max! like your code and explanation, should come in handy for some over stuff I am doing!

___________________

PHP Freak Wannabe!

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0088 seconds.