We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45366
    • 45 Posts
    For some reason some photo's that I upload to a gallery are appearing sideways - not all of them... if opened up in window's the appear the correct way, its just after they've been uploaded to the site that they go sideways.... not sure why this is.
      • 37110
      • 72 Posts
      That's because inside an image there is a rotation value.
      Your computer will rotate the image the right way if you made a photo and have the camera upsidedown.

      Gallery seems not to do anything with that and that's why the images are rotated.

      Below some code to rotate the image the right way. You have to implement that before gallery does anything with it.

      $exif = exif_read_data($uploadPath . $newFileName);
      if($exif && isset($exif['Orientation'])) {
      $orientation = $exif['Orientation'];
      if($orientation != 1){
      $img = imagecreatefromjpeg($uploadPath . $newFileName);
      $deg = 0;
      switch ($orientation) {
      case 3:
      $deg = 180;
      break;
      case 6:
      $deg = 270;
      break;
      case 8:
      $deg = 90;
      break;
      }
      if ($deg) {
      $img = imagerotate($img, $deg, 0);
      }
      // then rewrite the rotated image back to the disk as $filename
      imagejpeg($img, $uploadPath . $newFileName, 90);
      } // if there is some rotation necessary



      An other option is to use pThumb inside the chunks. pThumb will rotate the images the right way.
        • 45366
        • 45 Posts
        Thanks I'll see if I can work it smiley