D
D
Denis932022-03-15 18:54:28
PHP
Denis93, 2022-03-15 18:54:28

Why in opencart 2 some images are flipped when resizing?

when using model_tool_image->resize, some relatively heavy photos (3 mb) are flipped 90% to the left, who knows why and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2022-03-18
@Denis93

Experiments, add a method to the class https://github.com/opencart/opencart/blob/3567a9ac...

private function fixOrientationImage() {
    if (!extension_loaded('exif')) {
      exit('Error: PHP EXIF is not installed!');
    }
    
    $exif = exif_read_data($this->file, 0, true);
    
    if (isset($exif['IFD0']['Orientation'])) {
      switch($exif['IFD0']['Orientation']) {
        case 3:
          $this->rotate(180);
          break;
        case 6:
          $this->rotate(-90);
          break;
        case 8:
          $this->rotate(-180);
          break;
      }
    }
  }

add a line of code to the constructor https://github.com/opencart/opencart/blob/3567a9ac...
$this->fixOrientationImage();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question