dongshao1156 2015-01-11 11:27
浏览 56
已采纳

从目录加载图像后的PHP - 错误的方向

Actually i'm using a simple PHP snippet to iterate through a directory to grab images and insert them into the html markup.

Now im facing the problem that all images are oriented in landscape. So also portrait images are oriented as landscape images.

Here's my snippet:

    <?php 
    $projectpath = 'Projects';
    $projects = glob($projectpath . '/*' , GLOB_ONLYDIR);
    foreach($projects as $key=>$value): ?>
        <section class="project">
            <div class="container">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="project-images">
                            <?php 
                                $handle = opendir(dirname(realpath(__FILE__)).'/'.$value);
                                while($file = readdir($handle)){                                        
                                    if($file !== '.' && $file !== '..'){
                                        echo '<img class="img-responsive" alt="'. $file .'" src="'. $value .'/'. $file .'"/>';
                                    }
                                }                                                                    
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    <?php endforeach; ?>

So what do i'm missing here? Any suggestions?

  • 写回答

2条回答 默认 最新

  • doukai2839 2015-01-11 11:46
    关注

    I doubt those images really have different orientations. More likely all images are in landscape layout (greater width than height), so the visualization is correct from a technical point of view.

    I guess you usually look at the images with some viewer on your PC which auto rotates the images based on some orientation flag stored inside the images meta data. But such flag does not change the real, technical orientation (or better resolution). Instead such flag is only a hint for visualization of the images. Your project does not consult that flag, that is why your images appear to be rotated, whilst in reality they are not.

    So the solution is one of two options:

    1. rotate the images prior to using them inside your project, so that their real, technical orientation is correct and the images only have to be displayed without any additional rotation.

    2. use js or php or whatever to detect that orientation flag and evaluate it. Based on the outcome you can set some css class which results in a css based rotation of those images that need to be rotated for visualization.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示