5

On my site, users are able to upload images one at a time as nodes of content type Picture. The Picture content type uses the core (D7) image field.

Some of my users have pictures which are taken such that they need to be rotated 90 or 180 degrees. These users do not have easy access to image editing software, so I'd like to allow users to rotate the image on the edit node screen.

After the image is saved, I want to apply an image style (that forces scaling and cropping, etc.) I'm also using the Manual Crop module to allow users to crop the image if necessary.

Is there a module for this, or some easy way to do it in code? (I'm not a developer.)

I would prefer to have a solution where I can present users with a button to rotate the picture; I don't want to give them a full image editor.

If such a solution is impossible, is there an easy way to rotate the images on the back end (for admins)? I'm happy to do it myself, as I have to check all the images anyway.

2
  • In the media crop module, it says it can rotate the images. Does it not do that after image upload? There is a Drupal API image_rotate and a jquery UI plugin I am aware you mentioned, you ain't developer.
    – Minty
    Aug 3, 2012 at 20:02
  • Sorry, my mistake-- I'm using Manual Crop, not Media Crop. Media Crop requires CKEditor, which in turn requires a few other modules. I would prefer to just add a rotate option if possible. Aug 8, 2012 at 23:38

6 Answers 6

2

I found a way to fix the issue. I used the Image EXIF Autorotate module in conjunction with Imagecache Actions and Autorotate to apply autorotation as the image is being uploaded. Not after it is uploaded. So you will still need Imagecache Actions and Autorotate, this module just automates the process and applies autorotation without the need of an image style. Meaning you can use Manual Crop with it.

Note: that autorotate requires the Exif PHP extension to be enabled.

2

I've been fighting this issue for some hours now and have something that seems to work for me. It's not extensively tested yet, though.

My setup:

  • ImageMagick instead of GD as Image Toolkit (because GD strips EXIF data)
  • Imagecache Autorotate, part of [Imagecache Actions](Imagecache Autorotate) that provides an Image Action that automatically rotates pictures according to their EXIF orientation
  • EPSA Crop module: EPSA crop was the only cropping module that allowed me to use its after the Autorotate action in my image style preset (I tried at least with manualcrop, imagefield_crop, simplecrop)

In my image style I use the following actions:

  1. Autorotate Autorotate image based on its EXIF data
  2. EPSA Image Crop, 150x150 (with Aspect Ratio of one, as the resulting image has a square AR)
  3. Scale and Crop, 150x150, scale and crop it even if it wasn't manually cropped.

Only drawback so far: EPSA Crop doesn't show you the cropped image on the thumbnail of the edit page, so users might be confused if their cropping was successful after all.

Hope this helps others saving some hours of research.

1
+50

So, right now there is not a solid way to do this. I ran across quite a few requests for this feature and there is no working solution I can find that exists today. It would actually be worthwhile to write a module to accomplish this. I would be up to the task for sure, but I do not have any time at the present moment to do so. I would in a month or so though if you still do not have a viable solution. (I tried many different modules and lots of searching to find no existing solution in Node Edit. There are plenty that work with styles though.)

As for doing it in the administration, that would be very easy. All you need to do is apply a style to the image. Create 3 new styles. One rotates the image 90 deg clockwise, the other 90 deg counter-clockwise and the last rotates 180 degrees. When you are approving them, just apply the appropriate style by choosing the proper type.

See this Drupal Documentation on the subject.

Sorry for being wrong earlier. I am really disappointed in the modules that implement ImageMagick or even extend the GD. There really should be more node specific options exposed.

0
1

You can write a custom module that intercepts the file as it is being uploaded by the user, and saves it back to the Drupal schema. For that there's the Drupal Field Attachment API and Drupal File API. You will find that both APIs are meticulously documented. You use the Field Attachment API to implement a hook that gets the new (user uploaded) file URI as it is being uploaded (I think it was hook_field_attach_insert(), but I would need to verify my code). You use the File API (drupal_realpath()) to convert that URI into an absolute filesystem path that ImageMagick will understand (it doesn't accept relative paths).

Once ImageMagick has successfully loaded the file, the sky (or rather Imagick's API) is the limit. You'll need to save the modified file back into Drupal using the previously mentioned APIs. Both ImageMagick and GD libraries are well documented on the web.

I am personally not aware of an existing module that does this in D7? Although I admit it would be a nice to have. The only way I think this can can be done is with custom code, sorry.

2
  • Meta-response to my answer, implementing D7's Image API might be simpler (if using GD). Although my answer above represents what I am personally experienced with. Aug 6, 2012 at 5:16
  • I wouldn't do that personally. I would alter the node edit page to include image manipulation. Then I would just let it upload and then if the user decides to change it afterwards, I would create actions for imagemagick or GD based on the buttons exposed on the node edit page next to the image. If you did this, your upgrade path would be sustained and it should require the least amount of effort. Also, on my post I have given you the information you need to do this yourself in the admin screen, as requested. Aug 8, 2012 at 23:24
1

The Plupload integration module looks promising. Plupload supports client-side image resizing so it should work for your use case assuming one of the Drupal modules allow you to configure it as needed.

1

Simple Image rotate module may help you as it rotate image before upload

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.