排序肖像和风景图片 [英] Sorting portrait and landscape images
问题描述
是否有可能进行排序图像用PHP的数组。
Is it possible to sort an array of images with PHP.
作为例子,我有混合的横向和纵向的图像阵列。 140宽度的肖像和280景观。
As example I have array with mixed landscape and portrait images. 140 width for portrait and 280 for landscapes.
我想创建一个检查功能,如果位置1是纵向和位置2的风景,然后3位必须是倾情prevent差距在画廊。
I want to create a function which check if position 1 is portrait and position 2 landscape, then position 3 must be portrait to prevent gaps in the gallery.
推荐答案
使用和getimagesize检查纵向或横向
use getimagesize to check portrait or landscape
PHP code:
$size = getimagesize($filename);
$width = $size[0];
$height = $size[1];
$aspect = $height / $width;
if ($aspect >= 1) $mode = "vertical";
else $mode = "horizontal";
如果你想获得一个GD图像资源,而不是图像文件的大小,使用这种替代和getimagesize():
If you want to get the dimensions of a GD image resource rather than an image file, use this instead of getimagesize():
PHP code:
$width = imagesx($img);
$height = imagesy($img);
finaly,它实现到code和只是做一种希望
finaly, implement it to your code and just do a wished sort
这篇关于排序肖像和风景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!