diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm
index ccb1784dc..bf3e9bfd7 100644
--- a/lib/WebGUI/Asset/File/Image.pm
+++ b/lib/WebGUI/Asset/File/Image.pm
@@ -270,6 +270,7 @@ sub www_edit {
$self->getAdminConsole->addSubmenuItem($self->getUrl('func=resize'),$i18n->get("resize image")) if ($self->get("filename"));
$self->getAdminConsole->addSubmenuItem($self->getUrl('func=rotate'),$i18n->get("rotate image")) if ($self->get("filename"));
$self->getAdminConsole->addSubmenuItem($self->getUrl('func=crop'),$i18n->get("crop image")) if ($self->get("filename"));
+ $self->getAdminConsole->addSubmenuItem($self->getUrl('func=annotate'),$i18n->get("annotate image")) if ($self->get("filename"));
$self->getAdminConsole->addSubmenuItem($self->getUrl('func=undo'),$i18n->get("undo image")) if ($self->get("filename"));
my $tabform = $self->getEditForm;
$tabform->getTab("display")->template(
@@ -284,21 +285,275 @@ sub www_edit {
#-------------------------------------------------------------------
sub www_undo {
my $self = shift;
- my $previous = (@{$self->getRevisions()})[-2];
+ my $previous = (@{$self->getRevisions()})[1];
+ # instantiate assetId
if ($previous) {
+ warn("here");
+ # my $session = $self->session;
+ warn("here");
+
+ # my $cache = WebGUI::Cache->new($self->session, ["asset",$self->getId,$self->getRevisionDate]);
+ warn("here");
+ # $cache->flush;
+ warn("here");
+ # my $cache = WebGUI::Cache->new($previous->session, ["asset",$previous->getId,$previous->getRevisionDate]);
+ warn("here");
+ # $cache->flush;
+ warn("here");
+
+ warn("$previous");
+ warn(ref $previous);
+ warn($previous->getId);
$self = $self->purgeRevision();
+ # $self = undef;
+ warn("here");
+ # $self = WebGUI::Asset->new($previous->session, $previous->getId, ref $previous, $previous->getRevisionDate);
$self = $previous;
+ warn("$self");
+ warn(ref $self);
+ warn($self->getId);
+ warn($self->session->cache);
$self->generateThumbnail;
}
return $self->www_edit();
}
+#-------------------------------------------------------------------
+sub www_annotate {
+ my $self = shift;
+ return $self->session->privilege->insufficient() unless $self->canEdit;
+ return $self->session->privilege->locked() unless $self->canEditIfLocked;
+ if ($self->session->form->process("annotate_text")) {
+ my $newSelf = $self->addRevision();
+ delete $newSelf->{_storageLocation};
+ warn("here");
+ $newSelf->getStorageLocation->annotate($newSelf->get("filename"),$newSelf->session->form);
+ warn("here");
+ $newSelf->setSize($newSelf->getStorageLocation->getFileSize($newSelf->get("filename")));
+ warn("here");
+ $self = $newSelf;
+ warn("here");
+ $self->generateThumbnail;
+ warn("here");
+ }
+
+ my ($style, $url) = $self->session->quick(qw(style url));
+ # http://www.kryogenix.org/code/browser/annimg/annimg.html (creative commons)
+ $style->setLink($url->extras('annotate/imageMap.css'), {rel=>'stylesheet', type=>'text/css'});
+
+ my $imageAsset = $self->session->db->getRow("ImageAsset","assetId",$self->getId);
+
+ warn($imageAsset->{annotations});
+ my @pieces = split(/\n/, $imageAsset->{annotations});
+ # my ($top_left, $width_height, $note) = split(/\n/, $imageAsset->{annotations});
+
+ my $imageLoc = $self->getStorageLocation->getUrl($self->get("filename"));
+ my $image = '

';
+
+ my ($width, $height) = $self->getStorageLocation->getSize($self->get("filename"));
+
+ my $hotspots = "";
+ my $notes = "";
+ my @checkboxes = ();
+ my $i18n = WebGUI::International->new($self->session,"Asset_Image");
+ my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl);
+
+ my $mouseCoord_js = qq(
+
+ );
+
+ my $crop_js = qq(
+
+ );
+
+ for (my $i = 0; $i < $#pieces; $i += 3) {
+ my $top_left = $pieces[$i];
+ my $width_height = $pieces[$i + 1];
+ my $note = $pieces[$i + 2];
+
+ $hotspots .= qq(
+ dd#Def_${i} { $top_left }
+ dd#Def_$i a{ position: absolute; $width_height; text-decoration: none; border: 1px solid #FFFCE6; background: transparent url(/www/extras/annotate/note.png) repeat; }
+ dd#Def_$i a span{ display: none; }
+ dd#Def_$i a:hover{ background: transparent url(/www/extras/annotate/hover.png) repeat; border: 1px solid #BCBCBC; }
+ dd#Def_$i a:hover span{
+ display: block;
+ text-indent: 0;
+ vertical-align: top;
+ color: #000;
+ background-color: #F4F4F4;
+ font-weight: bold;
+ position: absolute;
+ border: 1px solid #BCBCBC;
+ bottom: 100%;
+ margin: 0;
+ padding: 5px;
+ width: 75%;
+ }
+ );
+
+ $notes .= qq(
+ $note
+ );
+
+ push(@checkboxes, $f->checkbox(
+ -label=>$i18n->get('delete') . " '$note'",
+ -checked=>0,
+ -name=>"delAnnotate$i",
+ -value=>"1"
+ )
+ );
+ $f->hidden(
+ -name=>"annotates",
+ -value=>"$i"
+ );
+ }
+
+ my $imageMap = qq(
+
+ );
+
+ my $imageCss = qq(
+
+ );
+ $self->getAdminConsole->addSubmenuItem($self->getUrl('func=edit'),$i18n->get("edit image"));
+ $f->hidden(
+ -name=>"func",
+ -value=>"annotate"
+ );
+ $f->text(
+ -label=>$i18n->get('annotate image'),
+ -value=>'',
+ -hoverHelp=>$i18n->get('annotate image description'),
+ -name=>'annotate_text'
+ );
+ $f->integer(
+ -label=>$i18n->get('top'),
+ -name=>"annotate_top",
+ -value=>,
+ );
+ $f->integer(
+ -label=>$i18n->get('left'),
+ -name=>"annotate_left",
+ -value=>,
+ );
+ $f->integer(
+ -label=>$i18n->get('width'),
+ -name=>"annotate_width",
+ -value=>,
+ );
+ $f->integer(
+ -label=>$i18n->get('height'),
+ -name=>"annotate_height",
+ -value=>,
+ );
+ $f->submit;
+ return $self->getAdminConsole->render($f->print."$mouseCoord_js\n$crop_js\n$imageCss\n$image\n$imageMap",$i18n->get("annotate image"));
+}
+
#-------------------------------------------------------------------
sub www_rotate {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
return $self->session->privilege->locked() unless $self->canEditIfLocked;
- warn ($self->session->form->process("degree"));
if (defined $self->session->form->process("degree")) {
my $newSelf = $self->addRevision();
delete $newSelf->{_storageLocation};
@@ -428,6 +683,7 @@ sub www_resize {
ghost: true,
status: true,
draggable: false,
+ ratio: true,
animate: true,
animateDuration: .75,
animateEasing: YAHOO.util.Easing.backBoth
diff --git a/lib/WebGUI/Storage.pm b/lib/WebGUI/Storage.pm
index 88c982944..f588ad5eb 100644
--- a/lib/WebGUI/Storage.pm
+++ b/lib/WebGUI/Storage.pm
@@ -678,6 +678,32 @@ sub generateThumbnail {
#-------------------------------------------------------------------
+=head2 getSize ( filename )
+
+Returns width and height of image.
+
+=head3 filename
+
+The file to generate a thumbnail for.
+
+=cut
+
+sub getSize {
+ my $self = shift;
+ my $filename = shift;
+ my $image = Image::Magick->new;
+ my $error = $image->Read($self->getPath($filename));
+ if ($error) {
+ $self->session->errorHandler->error("Couldn't read image for size reading: ".$error);
+ return 0;
+ }
+ my ($x, $y) = $image->Get('width','height');
+
+ return($x, $y);
+}
+
+#-------------------------------------------------------------------
+
=head2 getErrorCount ( )
Returns the number of errors that have been generated on this object instance.
@@ -1126,6 +1152,61 @@ sub crop {
#-------------------------------------------------------------------
+=head2 annotate ( filename [ text ] )
+
+Adds annotation text to the image.
+
+=head3 filename
+
+The name of the file to annotate.
+
+=head3 text
+
+Text to add.
+
+=cut
+
+sub annotate {
+ my $self = shift;
+ my $filename = shift;
+ my $form = shift;
+ warn("there");
+ unless (defined $filename) {
+ $self->session->errorHandler->error("Can't rotate when you haven't specified a file.");
+ return 0;
+ }
+ unless ($self->isImage($filename)) {
+ $self->session->errorHandler->error("Can't rotate something that's not an image.");
+ return 0;
+ }
+ warn("there");
+ # form->process("degree")
+ my $annotate_text = $form->process("annotate_text");
+ my $annotate_top = $form->process("annotate_top");
+ my $annotate_left = $form->process("annotate_left");
+ my $annotate_width = $form->process("annotate_width");
+ my $annotate_height = $form->process("annotate_height");
+ warn("there");
+ unless ($annotate_text) {
+ $self->session->errorHandler->error("Can't annotate with no text.");
+ return 0;
+ }
+ warn("there");
+
+ my $imageAsset = $self->session->db->getRow("ImageAsset","assetId",$self->getId);
+ if ($imageAsset->{annotations} =~ /\n/) {
+ $imageAsset->{annotations} .= "\n";
+ }
+ warn("there");
+ $imageAsset->{annotations} .= "top: ${annotate_top}px; left: ${annotate_left}px;\nwidth: ${annotate_width}px; height: ${annotate_height}px;\n$annotate_text";
+ $self->{_data}{annotations} = $self->{_data};
+ $self->session->db->setRow("ImageAsset","assetId",$self->{_data});
+
+ return 1;
+}
+
+#-------------------------------------------------------------------
+
=head2 rotate ( filename [ degrees ] )
Rotates the image by the specified degrees.
diff --git a/lib/WebGUI/i18n/English/Asset_Image.pm b/lib/WebGUI/i18n/English/Asset_Image.pm
index aece1fecd..ab39f38d0 100644
--- a/lib/WebGUI/i18n/English/Asset_Image.pm
+++ b/lib/WebGUI/i18n/English/Asset_Image.pm
@@ -77,6 +77,18 @@ shown here.|,
lastUpdated => 1106765841
},
+ 'annotate image' => {
+ message => q|Annotate Image|,
+ context => q|label to annotate the image|,
+ lastUpdated => 1106765841
+ },
+
+ 'annotate image description' => {
+ message => q|Text Around the Image|,
+ context => q|label to annotate the image|,
+ lastUpdated => 1106765841
+ },
+
'rotate image' => {
message => q|Rotate Image|,
context => q|label to rotate the image|,
@@ -125,6 +137,12 @@ shown here.|,
lastUpdated => 1106765841
},
+ 'delete' => {
+ message => q|Delete|,
+ context => q|label to delete annotation|,
+ lastUpdated => 1106765841
+ },
+
'height' => {
message => q|Height|,
context => q|label to resize the image|,