0

when user register with image. Now what i want to do is what ever rotation of the picture he uploaded, I just need to fetch all the user with there name and image. Here is the thing when fetching the details of the users i need image to be in the correct rotation. whether user uploaded in landscape or any angel i want it in correct. I have tried so many method like exif_read_data but it does not worked in the latest php and when i tried to dis on old version of the php it gives me the error Illegal IFD size. Is their another method to this. Let se the code.

<?php
$host="localhost";
$uname="root";
$upass="";
$link=mysqli_connect($host,$uname,$upass,"test");
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
 <script>
     $(document).ready(function() {
    var table = $('#example').DataTable();
} );
     </script>
    </head>
    <body>
      <table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Salary</th>
                <th>Image</th>
            </tr>
        </thead>
        <tbody>
           <?php

           $sql="select * from imageproblem";
           $result=mysqli_query($link,$sql) or die('mysqli error:query is wrong');
           while($row=mysqli_fetch_assoc($result))
           {
               echo '<tr>';
               echo '<td>';
               echo $row['id'];
               echo '</td>';
               echo '<td>';
               echo $row['name'];
               echo '</td>';
               echo '<td>';
               echo $row['salary'];
               echo '</td>';
               $destination='images/'.$row['image'];
               $exif = exif_read_data($destination);
if (!empty($exif['Orientation'])) {
  switch ($exif['Orientation']) {
    case 8:
      $command = 'mogrify -rotate "90" -auto-orient ' . $destination;
      exec("$command");
      break;
    case 3:
      $command = 'mogrify -rotate "180" -auto-orient ' . $destination;
      exec("$command");
      break;
    case 6:
      $command = 'mogrify -rotate "-90" -auto-orient ' . $destination;
      exec("$command");
      break;
  }
}
               echo '<td>';   
              echo '<img src="images/'.$row['image'].'" width="50" />';
               echo '</td>';
               echo '</tr>';
           }
           ?>
        </tbody>
    </table>
    </body>
</html>
  • You should sort the rotating out _before_ you store the image. Then you only need to rotate the image _once_ instead of everytime you're going to present it (which would be horrible for performance since modifying images takes both CSP and memory). You should also show us how you're trying to rotate the image using the exif-data. We're glad to help you sort out issues with your code, but then we need to see the code causing the issues. – M. Eriksson Jun 16 '19 at 11:27
  • @MagnusEriksson I have given the code. See it carefully. – Lomas Sharma Jun 16 '19 at 11:28
  • I am fetching the user details and in table user is multiple and it means there will be the image of the every user. Thats why i added it on the loop. Correct me if i am wrong. – Lomas Sharma Jun 16 '19 at 11:30
  • I have no idea what the command `mogrify` that you're calling through the command line is. Why don't you just rotate the image once on save? It can also be done in PHP. – M. Eriksson Jun 16 '19 at 11:35
  • @MagnusEriksson The task is fetch the user details and make the picture in correct orientation. And really i do not know what should i do for that suggest me the code what will be the code for that and how. Which will better method to do this. – Lomas Sharma Jun 16 '19 at 11:39
  • Possible duplicate of [PHP read\_exif\_data and Adjust Orientation](https://stackoverflow.com/questions/7489742/php-read-exif-data-and-adjust-orientation) – M. Eriksson Jun 16 '19 at 11:46
  • @MagnusEriksson i tried new thing but its shows the entire website black here is the code->$filename = 'images/'.$row['image']; $degrees = 90; $image_size= getimagesize($filename); $width=$image_size[0]; $height=$image_size[1]; if($width < $height) { // Content type header('Content-Type: image/jpeg'); // Load $source = imagecreatefromjpeg($filename); // Rotate $rotate = imagerotate($source, $degrees, 0); // Output imagejpeg($rotate,$filename); } else { echo 'landscape'; } – Lomas Sharma Jun 16 '19 at 11:47
  • @MagnusEriksson This is not the solution – Lomas Sharma Jun 16 '19 at 12:10
  • Please elaborate... – M. Eriksson Jun 16 '19 at 16:12

0 Answers0