Rotating and cropping are two basic photo-editing actions. Image Uploader provides the built-in image editor to perform these actions manually, you can also configure Image Uploader to rotate and crop images automatically. This topic consists of two parts, namely, rotating images and cropping images, each tells how to configure Image Uploader to upload edited versions of images and edit images automatically.
There are two approaches to rotating images in Image Uploader:
By default manual rotation is enabled in Image Uploader. It means that a user can rotate images either by clicking the rotation control or using the image editor. To upload rotated images you just need to specify a Converter with Thumbnail Mode, as it is shown in the example below.
<aur:Uploader ID="Uploader1" runat="server"> <Converters> <aur:Converter Mode="*.*=Thumbnail" ThumbnailFitMode="ActualSize" /> </Converters> </aur:Uploader>
$uploader = new Uploader("Uploader1"); $converters = &$uploader->getConverters(); $converter = new Converter(); $converter->setMode("*.*=Thumbnail"); $converter->setThumbnailFitMode("ActualSize"); $converters[] = $converter;
var u = $au.uploader({ id: 'Uploader1', converters: [{mode: '*.*=Thumbnail', thumbnailFitMode: 'ActualSize'}] });
You may also get rotation angle value on the server and handle it in a way that suites your requirements, for more information, please, see the receiving rotation angle paragraph.
To disable manual image rotation set the Uploader.EnableRotation property to false
.
Automatic rotation means that Image Uploader rotates images automatically, if needed. The decision, whether to
rotate an image or not, is based on the EXIF metadata contained in the original image. To turn automatic rotation on you have to set the
Uploader.EnableAutoRotation property to true
and add a
Thumbnail converter, as it is shown in the following example.
<aur:Uploader ID="Uploader1" runat="server" EnableAutoRotation="true"> <Converters> <aur:Converter Mode="*.*=Thumbnail" ThumbnailFitMode="ActualSize" /> </Converters> </aur:Uploader>
$uploader = new Uploader("Uploader1"); $uploader->setEnableAutoRotation(true); $converters = &$uploader->getConverters(); $converter = new Converter(); $converter->setMode("*.*=Thumbnail"); $converter->setThumbnailFitMode("ActualSize"); $converters[] = $converter;
var u = $au.uploader({ id: 'Uploader1', enableAutoRotation: true, converters: [{mode: '*.*=Thumbnail', thumbnailFitMode: 'ActualSize'}] });
Though it may be convenient, remember that not all the cameras recognize orientation properly. Reading EXIF data also slows down the process of folder scanning, and if the folder contains a lot of images, the decrease in speed may be noticeable.
This paragraph describes main approaches to cropping in Image Uploader:
A user can crop images via the image editor. When a user crops an image this way, Image Uploader saves
the crop bounds. To upload cropped images you have to create a Thumbnail converter and set its
ThumbnailApplyCrop property to true
, like it is shown in the
following example.
<aur:Uploader ID="Uploader1" runat="server" > <Converters> <aur:Converter Mode="*.*=Thumbnail" ThumbnailFitMode="ActualSize" ThumbnailApplyCrop="true" /> </Converters> </aur:Uploader>
$uploader = new Uploader("Uploader1"); $converters = &$uploader->getConverters(); $converter = new Converter(); $converter->setMode("*.*=Thumbnail"); $converter->setThumbnailFitMode("ActualSize"); $converter->setThumbnailApplyCrop(true); $converters[] = $converter;
var u = $au.uploader({ id: 'Uploader1', converters: [{mode: '*.*=Thumbnail', thumbnailFitMode: 'ActualSize', thumbnailApplyCrop: true}] });
This paragraph describes how to crop each user-selected image automatically. Automatic cropping consists of two parts:
true
.The following example crops 200 x 200 pixels rectangle out of the center of each user-selected image.
<script type="text/javascript"> function beforeUploadHandler(){ var cropWidth = 200; var cropHeight = 200; var count = $au.uploader('Uploader1').files().count(); for (var i=0; i < count; i++) { var $file = $au.uploader('Uploader1').files().get(i); var imageCenterX = $file.width() / 2; var imageCenterY = $file.height() / 2; var cropBounds = [(imageCenterX - cropWidth/2), (imageCenterY - cropHeight/2), cropWidth, cropHeight]; $file.cropBounds(cropBounds); } } </script> <aur:Uploader ID="Uploader1" runat="server" > <Converters> <aur:Converter Mode="*.*=Thumbnail" ThumbnailFitMode="ActualSize" ThumbnailApplyCrop="true" /> </Converters> <ClientEvents> <aur:ClientEvent EventName="BeforeUpload" HandlerName="beforeUploadHandler" /> </ClientEvents> </aur:Uploader>
<script type="text/javascript"> function beforeUploadHandler(){ var cropWidth = 200; var cropHeight = 200; var count = $au.uploader('Uploader1').files().count(); for (var i=0; i < count; i++) { var $file = $au.uploader('Uploader1').files().get(i); var imageCenterX = $file.width() / 2; var imageCenterY = $file.height() / 2; var cropBounds = [(imageCenterX - cropWidth/2), (imageCenterY - cropHeight/2), cropWidth, cropHeight]; $file.cropBounds(cropBounds); } } </script> <?php $uploader = new Uploader("Uploader1"); $converters = &$uploader->getConverters(); $converter = new Converter(); $converter->setMode("*.*=Thumbnail"); $converter->setThumbnailFitMode("ActualSize"); $converter->setThumbnailApplyCrop(true); $converters[] = $converter; $uploader->getClientEvents()->setBeforeUpload("beforeUploadHandler"); $uploader->render(); ?>
function beforeUploadHandler(){ var cropWidth = 200; var cropHeight = 200; var count = this.files().count(); for (var i=0; i < count; i++) { var $file = this.files().get(i); var imageCenterX = $file.width() / 2; var imageCenterY = $file.height() / 2; var cropBounds = [(imageCenterX - cropWidth/2), (imageCenterY - cropHeight/2), cropWidth, cropHeight]; $file.cropBounds(cropBounds); } } var u = $au.uploader({ id: 'Uploader1', converters: [{mode: '*.*=Thumbnail', thumbnailFitMode: 'ActualSize', thumbnailApplyCrop: true}], events: { beforeUpload: beforeUploadHandler } });
Selecting an image area to highlight a person or an object is a quite popular idea in social networking. In Image Uploader a user actually selects a rectangular area of an image while cropping this image. Bounds of this rectangle will be uploaded along with the image, no matter what converter mode you use (in this case you can set SourceFile mode). So, on the server side you may receive user-given selection and show the highlighted area on the image.
To get to know how to obtain crop bounds on the server side, please, see the receiving crop bounds paragraph.