ruzD ruzD - 1 month ago 15
PHP Question

PHP - Process vertical image take from iPhone

I have made a site to take a photo, it convert to square and it merge with other image. The site is working fine but I have a problem, a big problem.

The pictures to take from iPhone in vertical really are in horizontal. Then when it convert and it merge the image show wrong rotate :(

Ex: iPhone take a vertical photo:

enter image description here

Really the vertical photo is:

enter image description here

This photos when I open from mac is showed fine but when is open from another plataform (win or linux) is showed in horizontal. For this I think that this images contain any data to identify it.

The php code is this: (I think that the code is correct, Just need to put any instruction to recognize the orientation)

$file = $_FILES['image1']['name'];

list($x, $y) = getimagesize($file);

echo "MEDIDAS";
echo "<br>";
echo "x: ".$x;
echo "<br>";
echo "y: ".$y;
echo "<br>";

// horizontal rectangle
if ($x > $y) {
$square = $y; // $square: square side length
$offsetX = ($x - $y) / 2; // x offset based on the rectangle
$offsetY = 0; // y offset based on the rectangle
$grados = 270;
echo "Horizontal rectangle";
// vertical rectangle
elseif ($y > $x) {
$square = $x;
$offsetX = 0;
$offsetY = ($y - $x) / 2;
$grados = 270;
echo "Vertical rectangle";
// it's already a square
else {
$square = $x;
$offsetX = $offsetY = 0;
$grados = 0;
echo "Cuadrat";


Sorry, this issue is very difficult to explain it.

Could you help me?


The orientation is stored in the exif data. You should extract that information from the image and rotate that image accordingly. Here you can find some code that might help you. And here you can find the exif orientation values and their meanings.