piixeldesigns
asked on
Facebook image proportions question
Hey All,
I have a quick question about my website and facebook's website. With their profile photos, if someone sets a portrait photo as a profile photo they zoom in on it to still maintain that nice square shape throughout all of their profile photos/albums etc...
I am needing an exact function like this on my website and what I currently have I don't think is working correctly. Please check out my code below:
And this is my function it's self:
Any help on this or ideas on how to get this to work like Facebooks so I can maintain a perfect size at all times in a preferable landscape size (almost square) even for portrait photos.
Thanks in Advance!
I have a quick question about my website and facebook's website. With their profile photos, if someone sets a portrait photo as a profile photo they zoom in on it to still maintain that nice square shape throughout all of their profile photos/albums etc...
I am needing an exact function like this on my website and what I currently have I don't think is working correctly. Please check out my code below:
imageurl($profile_image,192,192); //This is my function in my site
And this is my function it's self:
function imageurl($imagepath,$width,$height) //function for bind image
{
if($imagepath == "")
{
echo "<img src='uploads/1.gif' width='".$width."' height='" .$height. "' />";
}
else
{
if (file_exists('uploads/'. $imagepath))
{
echo "<img src='uploads/".$imagepath."' width='".$width."' height='" .$height. "' alt='' />";
}
else
{
echo "<img src='uploads/1.gif' width='".$width."' height='" . $height. "' />";
}
}
}
Any help on this or ideas on how to get this to work like Facebooks so I can maintain a perfect size at all times in a preferable landscape size (almost square) even for portrait photos.
Thanks in Advance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NOTE: if you replace the img portion of Example 6 with below OR determine which dimension is greater to begin with use the greater of the two dimensions to determine whether you scale by width OR height (not both)
For my landscape image height=192 fills out the 192x192 box.
<IMG style="position:relative; top: -0px;left:-150px" SRC=test.jpg height=192>
For my landscape image height=192 fills out the 192x192 box.
<IMG style="position:relative; top: -0px;left:-150px" SRC=test.jpg height=192>
ASKER
Thanks for the help
ASKER
Thanks Again everyone for your help! :)
To match Facebook's functionality:
first scale the image so that one of the dimensions fits into your 192x192 box
allow the user to center the image in a 192x192 box
save the area of the image in that 192x192 box and save the scaled original image
This can be done with imagemagik through PHP or using HTML or possibly many other methods.
The HTML code below produces the picture shown. I think the last example is the one you want. When I get pictures for a website I still scale them down first with imagemagik because they are usually too large to start with.
NOTE: copy the code to a file and save as test.html and pick a picture you want to test with and call it test.jpg and put it in the same directory as test.html to test.
Open in new window
Screenshot-23.png