Skip to content

Rotate jpeg images based on exif data #19

Open
@taravasya

Description

@taravasya

Hello! Thanks for your greate code! Im just want to propose some little new feature(as it sayed in issue title). For this just need to add one more argument to your function:
$exifrotation = false
and then after existing string(at line 91):

imagecopyresampled($image_resized, $image, 0, 0, $cropWidth, $cropHeight, $final_width, $final_height, $width_old - 2 * $cropWidth, $height_old - 2 * $cropHeight);

add liitle peace of code:

	if ($exifrotation && $info[2] == IMAGETYPE_JPEG) {
	$exif = exif_read_data($file);
        if (!empty($exif['Orientation'])) {
            switch ($exif['Orientation']) {
                case 3:
                    $image_resized = imagerotate($image_resized, 180, 0);
                    break;

                case 6:
                    $image_resized  = imagerotate($image_resized, -90, 0);
                    break;

                case 8:
                    $image_resized  = imagerotate($image_resized, 90, 0);
                    break;
            }
        }
	}

Sorry what Im not crete new PR(its because I`m not so oriented for this things ))) )
And.. also may be this code not good enough for new PR.
Anyway thank you! ))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions