Welcome Guest, Not a member yet? Register   Sign In
Image_moo will resize but not rotate (without errors) [SOLVED]
#1

[eluser]machouinard[/eluser]
I'm trying to use image_moo to rotate images according their EXIF ORIENTATION tag. Here's the code:
Code:
private function __fix_rotation($image){
  $this->image_moo->load($image);
  $exif = exif_read_data($image);
  $this->image_moo->set_background_colour("#FFFFFF");
   print_array($exif, 'EXIF read from $image');//(Custom print_r function) - reads EXIF as expected

  $orient = $exif['Orientation'];
  switch($orient)
  {
   case 1: // none
    break;
   case 3: // 180 rotate
    $this->image_moo->rotate(180);
    break;
   case 6: // 90 rotate right
    $this->image_moo->rotate(270);
    break;
   case 8:    // 90 rotate left
    $this->image_moo->rotate(90);
    break;
  }
  
  $this->image_moo->save($image, TRUE);

}
It reads the EXIF from the image like it should, but after that I get this error
Code:
A PHP Error was encountered

Severity: 4096

Message: Object of class Image_moo could not be converted to string

Filename: libraries/image_moo.php

Line Number: 670

If I change it from rotate(270) to resize(500, 500) it works just fine.

Can anyone see a flaw in the code here? I'm stumped.

Thanks,

Mark
#2

[eluser]vbsaltydog[/eluser]
Why not just use the CI image library?

http://ellislab.com/codeigniter/user-gui...e_lib.html
#3

[eluser]Mat-Moo[/eluser]
Sounds like the image is not being loaded, try and use
Code:
if($this->image_moo->error) print $this->image_moo->display_errors();.
after the image load.

Also guessing that image-moo is loaded somewhere else...
#4

[eluser]machouinard[/eluser]
Guess I left out the part about the rotation actually working despite the errors. Blame it 30 some hours without sleep.

So yes, the image is being loaded. It's even being rotated. I just can't figure out where the errors are coming from.

I've checked again and again, and image_moo is being loaded only once. Currently in autoload.php, but I've also tried loading it in the function. Makes no difference where it's loaded.

I'm using image_moo in only two functions. First to rotate the image based on the ORIENTATION tag (above), then to create a thumbnail
Code:
function make_thumb($file_name, $image){
  $thumb = 'images/test/thumbs/'.$file_name;
  $this->image_moo->load($image)->resize(150, 150)->save($thumb, TRUE);
  
  return $thumb;
}

I've replaced image_moo.php with a fresh copy, but no change.

And I assume you meant
Code:
if($this->image_moo->errors)
with errors, plural? Anyhow, it does not display anything.

I'm sure it's something ridiculously simple I'm missing, I'm just not seeing it. I have a nearly identical situation on another site and I'm getting no errors there, so I know it should work.
#5

[eluser]machouinard[/eluser]
Thanks for the help, Mat-Moo!

For anyone else who might find themselves struggling with this:

image_moo v1.01 there's an extra $ on line 670
Code:
$col = $this->_html2rgb($$this->background_colour);

And vbsaltydog, I guess I just prefer to use image_moo. In my experience it's much cleaner and more versatile.

Vive le image_moo!




Theme © iAndrew 2016 - Forum software by © MyBB