Is there a way to determine an image's width and height from a URL or something else?
What I want to do is load an image and resize (scale proportionally) it to fit the layout.
[updated]
Thanks to your comments I got this working for my needs. Thanks everyone.
my testing code
<?php
//image sizing
$imgurl = "http://www.domain.com/images/image.jpg";
$img = @imagecreatefromjpeg($imgurl);
if ($img) {
$img_height = imagesy($img);
$img_width = imagesx($img);
// imagedestroy($img);
}
echo "My width is " . $img_width;
echo "My height is " . $img_height;
$scale = 200 / $img_width;
$img_xnew ="200";
$img_ynew = round($scale * $img_height);
print("<hr><img src=$imgurl border=1>");
print("<br>$imgurl");
print("<br>scale $scale");
print("<br>$img_xnew x $img_ynew");
print("<hr><img src=$imgurl width=$img_xnew height=$img_ynew border=1>");
?>
What I want to do is load an image and resize (scale proportionally) it to fit the layout.
[updated]
Thanks to your comments I got this working for my needs. Thanks everyone.
my testing code
<?php
//image sizing
$imgurl = "http://www.domain.com/images/image.jpg";
$img = @imagecreatefromjpeg($imgurl);
if ($img) {
$img_height = imagesy($img);
$img_width = imagesx($img);
// imagedestroy($img);
}
echo "My width is " . $img_width;
echo "My height is " . $img_height;
$scale = 200 / $img_width;
$img_xnew ="200";
$img_ynew = round($scale * $img_height);
print("<hr><img src=$imgurl border=1>");
print("<br>$imgurl");
print("<br>scale $scale");
print("<br>$img_xnew x $img_ynew");
print("<hr><img src=$imgurl width=$img_xnew height=$img_ynew border=1>");
?>
