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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献