Welcome, Guest! Log In | Create Account

Ticket #265 (new enhancement)

Opened 9 months ago

Last modified 3 weeks ago

Rotate images based on EXIF rotation information

Reported by: bharat Owned by:
Priority: major Milestone: Field of Dreams
Version: GIT HEAD Keywords:
Cc: griffinmt, floridave, mamoun.diraneyya@…

Description

When uploading, if we can figure out the proper orientation, rotate the image accordingly.

Change History

  Changed 9 months ago by bharat

  Changed 9 months ago by bharat

  • milestone changed from 3.0 Beta 1 to 3.0 Beta 2

  Changed 9 months ago by jstricker

I was able to achieve the functionality I described in my original forum post (http://gallery.menalto.com/node/87618#comment-307385) by adding three things. It's certainly not ideal, but it works.

1. Install PEL (http://pel.sourceforge.net/) in modules\exif\lib\pel

2. Add the following to modules\exif\helpers\exif_installer.php in the install() function:

  foreach (array("thumb", "resize") as $target) {
        $rule = ORM::factory("graphics_rule");
        $rule->module_name = "exif";
        $rule->target = $target;
        $rule->operation = "exif_rotate";
        $rule->priority = 200;
        $rule->save();
  }

3. Add the following function to core\helpers\graphics.php:

/**
 * Rotate an image based on the file's EXIF data.  The options parameter is ignored.
 *
 * @param string     $input_file
 * @param string     $output_file
 * @param array      $options
 */
static function exif_rotate($input_file, $output_file, $options) {
	require_once(MODPATH . "exif/lib/pel/PelJpeg.php");
	$data = new PelDataWindow(file_get_contents($input_file));
	if (PelJpeg::isValid($data)) {
		$jpeg = new PelJpeg();
		$jpeg->load($data);
		if ($jpeg != null) {
			$exif = $jpeg->getExif();
			if ($exif != null) {
				$tiff = $exif->getTiff();
				if ($tiff != null) {
					$ifd0 = $tiff->getIfd();
					if ($ifd0 != null) {
						$orientation = $ifd0->getEntry(PelTag::ORIENTATION);
						if ($orientation != null) {
							$angle = 0;
							switch ($orientation->getValue()) {
								case 6:
									$angle = 90;
									break;
								case 8:
									$angle = -90;
									break;
							}
							if ($angle != 0) {
								$orientation->setValue(0);
								file_put_contents($output_file, $jpeg->getBytes());
								self::rotate($output_file , $output_file, array("degrees" => $angle));
							}
						}
					}
				}
			}
		}
	}
}

  Changed 7 months ago by tnalmdal

  • milestone changed from 3.0 Beta 2 to 3.1

  Changed 4 months ago by faucon

  • priority changed from minor to major

Is this really Milestone 3.1? This is not a minor priority. Looking at facebook, flicker and other, there are soooo much pictures with different orientation here. Minor? Really? 3.1? Really?

Just refresh here a couple of time for references http://www.flickr.com/explore/interesting/7days/

  Changed 4 months ago by tnalmdal

  • milestone changed from 3.1 to Field of Dreams

follow-ups: ↓ 8 ↓ 10   Changed 4 months ago by tnalmdal

Not sure this is required, probably better off as a -contrib module so that if someone requires it, then can choose to add it, and not impact the rest of u that don't need it.

in reply to: ↑ 7   Changed 4 months ago by griffinmt

  • cc griffinmt added

Replying to tnalmdal:
Clearly 50% of the photos I deal with are oriented as portrait (some left - some right). I have to manually work through the various albums to search them out and rotate manually. This is a slow and wastefull hunk of time when one considers that is can be done programmatically and in fact is done with most applications, such as Picasa.
I would do it myself if I could get some assistance navigating through the maze of modules and folders that seems to be in place.

  Changed 4 months ago by u3b54

Neither the jhead solution or the solution above are doing anything for me. I need to do some work to nail down why.

In terms of milestone roadmap for this feature request, I'd suggest that it really should go into the earliest possible release. I, for example, am trying to replace jAlbum with Gallery for providing my school's photo gallery for parents and children on the net. I have nearly 30,000 images to put up. Gallery 2 does the auto-rotate, but, IMHO, is pretty ugly. I'm happy with the look and feel of 3, even with the default theme, but there's no way I'm going to go through the 30,000 pics rotating them all by hand. 90% of them are portrait orientation.

in reply to: ↑ 7   Changed 4 months ago by faucon

Replying to tnalmdal:

Not sure this is required, probably better off as a -contrib module so that if someone requires it, then can choose to add it, and not impact the rest of u that don't need it.

I am not sure to follow you on this one. Nevertheless, if you are speaking about, "should this be an option?", well yes I am totally for that. Just like G2, this is an option in the EXIF/IPTC plugin.

Since you are a photographer, you know what I am talking about http://www.timalmdal.com/v/places/B008588.jpg.html

Would it be more easy to just take the code of the G2 and use it in G3?

  Changed 4 weeks ago by floridave

  • cc floridave added

  Changed 3 weeks ago by mamouneyya

  • cc mamoun.diraneyya@… added
Note: See TracTickets for help on using tickets.