How do I get images in certain fixed size, example I've attached the image and codes for your review
如何获取特定固定大小的图像,例如我已附加图像和代码供您查看
Please click on this link (image) to understand my question
请点击此链接(图片)以了解我的问题
<img src="<?php echo $picfile; ?>" border="0" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>" align="left" style="border:1px solid black;margin-right:5px;">
4 个解决方案
#1
2
You can get image details with
您可以使用获取图像详细信息
$details = get_image_size($filename).
$details[3] will contain the width and height in html format ready for you to use.
$ details [3]将包含html格式的宽度和高度,供您使用。
#2
1
Could possibly try this
可能试试这个
img src='$filename' style='width:250px; height: 250px'
allows you to strech image to specific size
允许您将图像拉伸到特定大小
to scale you could use
按比例你可以使用
img src='$filename' style='width:auto; height: 250px'
#3
1
There are a few ways to do this. As you are looping through your images, you want to keep track of the maximum width.
有几种方法可以做到这一点。在循环显示图像时,您需要跟踪最大宽度。
$newImageArray = array();
$maxWidth = 0;
$maxHeight = 0;
$i = 0;
forEach ( $imageArray as $picfile ) {
$newImageArray[$i]['picFile'] = $picfile;
$imgsize = get_image_size($picfile);
$newImageArray[$i]['width'] = $imgsize[0];
if ( $imgsize[0] > $maxWidth ) {
$maxWidth = $imgsize[0];
}
$newImageArray[$i]['height'] = $imgsize[1];
if ( $imgsize[1] > $maxHeight ) {
$maxHeight = $imgsize[1];
}
$1++;
}
forEach ( $newImageArray as $i) { ?>
<img src="<?php echo $picfile; ?>" border="0" width="<?php echo $maxWidth; ?>" height="<?php echo $maxHeight; ?>" align="left" style="border:1px solid black;margin-right:5px;">
<?php
}
Now you shouldn't really be doing this. A CSS based option would work better. You can add a wrapper container with a width on it and set the images to display:block;width:100%; and the images will always fill the space. I will edit with that solution shortly.
现在你不应该真的这样做。基于CSS的选项可以更好地工作。您可以添加一个宽度在其上的包装容器,并将图像设置为display:block; width:100%;并且图像将始终填满空间。我将很快编辑该解决方案。
This will keep the image within a fixed width, and scale the image to fit inside of the box when it is too large.
这将使图像保持固定的宽度,并在图像太大时缩放图像以适合框内部。
HTML:
<div class="imgWrap">
<img src="http://www.captainangry.com/img/1236647133510anonib.jpg">
</div>
CSS:
.imgWrap {
width:100px;
height:100px;
float:left;
}
.imgWrap img {
display:block;
max-width:100%;
}
#4
0
If you don't want to do any work in PHP then just wrap the image in a div and set overflow:hidden
. This assumes that you know the height you want all of your images to be.
如果你不想在PHP中做任何工作,那么只需将图像包装在div中并设置overflow:hidden。这假定您知道所有图像的高度。
<div style="width:<?php echo $imgsize[0]; ?>; height:100px; overflow:hidden; border:1px solid black; margin-right:5px">
<img src="<?php echo $picfile; ?>" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>">
</div>
#1
2
You can get image details with
您可以使用获取图像详细信息
$details = get_image_size($filename).
$details[3] will contain the width and height in html format ready for you to use.
$ details [3]将包含html格式的宽度和高度,供您使用。
#2
1
Could possibly try this
可能试试这个
img src='$filename' style='width:250px; height: 250px'
allows you to strech image to specific size
允许您将图像拉伸到特定大小
to scale you could use
按比例你可以使用
img src='$filename' style='width:auto; height: 250px'
#3
1
There are a few ways to do this. As you are looping through your images, you want to keep track of the maximum width.
有几种方法可以做到这一点。在循环显示图像时,您需要跟踪最大宽度。
$newImageArray = array();
$maxWidth = 0;
$maxHeight = 0;
$i = 0;
forEach ( $imageArray as $picfile ) {
$newImageArray[$i]['picFile'] = $picfile;
$imgsize = get_image_size($picfile);
$newImageArray[$i]['width'] = $imgsize[0];
if ( $imgsize[0] > $maxWidth ) {
$maxWidth = $imgsize[0];
}
$newImageArray[$i]['height'] = $imgsize[1];
if ( $imgsize[1] > $maxHeight ) {
$maxHeight = $imgsize[1];
}
$1++;
}
forEach ( $newImageArray as $i) { ?>
<img src="<?php echo $picfile; ?>" border="0" width="<?php echo $maxWidth; ?>" height="<?php echo $maxHeight; ?>" align="left" style="border:1px solid black;margin-right:5px;">
<?php
}
Now you shouldn't really be doing this. A CSS based option would work better. You can add a wrapper container with a width on it and set the images to display:block;width:100%; and the images will always fill the space. I will edit with that solution shortly.
现在你不应该真的这样做。基于CSS的选项可以更好地工作。您可以添加一个宽度在其上的包装容器,并将图像设置为display:block; width:100%;并且图像将始终填满空间。我将很快编辑该解决方案。
This will keep the image within a fixed width, and scale the image to fit inside of the box when it is too large.
这将使图像保持固定的宽度,并在图像太大时缩放图像以适合框内部。
HTML:
<div class="imgWrap">
<img src="http://www.captainangry.com/img/1236647133510anonib.jpg">
</div>
CSS:
.imgWrap {
width:100px;
height:100px;
float:left;
}
.imgWrap img {
display:block;
max-width:100%;
}
#4
0
If you don't want to do any work in PHP then just wrap the image in a div and set overflow:hidden
. This assumes that you know the height you want all of your images to be.
如果你不想在PHP中做任何工作,那么只需将图像包装在div中并设置overflow:hidden。这假定您知道所有图像的高度。
<div style="width:<?php echo $imgsize[0]; ?>; height:100px; overflow:hidden; border:1px solid black; margin-right:5px">
<img src="<?php echo $picfile; ?>" width="<?php echo $imgsize[0]; ?>" height="<?php echo $imgsize[1]; ?>">
</div>