check point

This commit is contained in:
Brian Medley 2009-02-19 18:32:57 +00:00
parent d4fb48f77d
commit 482267b8af
4 changed files with 209 additions and 2 deletions

View file

@ -245,11 +245,13 @@ sub getEditFormUploadControl {
return $html;
}
#-------------------------------------------------------------------
sub getFileUrl {
my $self = shift;
#return $self->get("url");
if (-f $self->getStorageLocation->getPath('crop-' . $self->get("filename"))) {
return $self->getStorageLocation->getUrl('crop-' . $self->get("filename"));
}
return $self->getStorageLocation->getUrl($self->get("filename"));
}
@ -562,7 +564,7 @@ sub www_edit {
sub www_view {
my $self = shift;
return $self->session->privilege->noAccess() unless $self->canView;
# Check to make sure it's not in the trash or some other weird place
if ($self->get("state") ne "published") {
my $i18n = WebGUI::International->new($self->session,'Asset_File');

View file

@ -268,6 +268,7 @@ sub www_edit {
return $self->session->privilege->locked() unless $self->canEditIfLocked;
my $i18n = WebGUI::International->new($self->session, 'Asset_Image');
$self->getAdminConsole->addSubmenuItem($self->getUrl('func=resize'),$i18n->get("resize image")) if ($self->get("filename"));
$self->getAdminConsole->addSubmenuItem($self->getUrl('func=crop'),$i18n->get("crop image")) if ($self->get("filename"));
my $tabform = $self->getEditForm;
$tabform->getTab("display")->template(
-value=>$self->get("templateId"),
@ -320,6 +321,108 @@ sub www_resize {
return $self->getAdminConsole->render($f->print.$image,$i18n->get("resize image"));
}
#-------------------------------------------------------------------
# feel free to take over typing
sub www_crop {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
return $self->session->privilege->locked() unless $self->canEditIfLocked;
if ($self->session->form->process("Width") || $self->session->form->process("Height")
|| $self->session->form->process("Top") || $self->session->form->process("Left")) {
my $newSelf = $self->addRevision();
delete $newSelf->{_storageLocation};
$newSelf->getStorageLocation->crop(
$newSelf->get("filename"),
$newSelf->session->form->process("Width"),
$newSelf->session->form->process("Height"),
$newSelf->session->form->process("Top"),
$newSelf->session->form->process("Left")
);
$self = $newSelf;
}
my $filename = $self->get("filename");
##YUI specific datatable CSS
my ($style, $url) = $self->session->quick(qw(style url));
my $crop_js = qq(
<script>
(function() {
var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event, results = null;
Event.onDOMReady(function() {
var crop = new YAHOO.widget.ImageCropper('yui_img', {
initialXY: [20, 20],
keyTick: 5,
shiftKeyTick: 50
});
crop.on('moveEvent', function() {
var region = crop.getCropCoords();
element = document.getElementById('Width_formId');
element.value = region.width;
element = document.getElementById('Height_formId');
element.value = region.height;
element = document.getElementById('Top_formId');
element.value = region.top;
element = document.getElementById('Left_formId');
element.value = region.left;
});
});
})();
</script>
);
$style->setLink($url->extras('yui/build/resize/assets/skins/sam/resize.css'), {rel=>'stylesheet', type=>'text/css'});
$style->setLink($url->extras('yui/build/fonts/fonts-min.css'), {rel=>'stylesheet', type=>'text/css'});
$style->setLink($url->extras('yui/build/imagecropper/assets/skins/sam/imagecropper.css'), {rel=>'stylesheet', type=>'text/css'});
$style->setScript($url->extras('yui/build/yahoo-dom-event/yahoo-dom-event.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/element/element-beta-min.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/dragdrop/dragdrop-min.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/resize/resize-min.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/imagecropper/imagecropper-beta-min.js'), {type=>'text/javascript'});
my $i18n = WebGUI::International->new($self->session,"Asset_Image");
$self->getAdminConsole->addSubmenuItem($self->getUrl('func=edit'),$i18n->get("edit image"));
my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl);
$f->hidden(
-name=>"func",
-value=>"crop"
);
my ($x, $y) = $self->getStorageLocation->getSizeInPixels($filename);
$f->integer(
-label=>$i18n->get('width'),
-hoverHelp=>$i18n->get('new width description'),
-name=>"Width",
-value=>$x,
);
$f->integer(
-label=>$i18n->get('height'),
-hoverHelp=>$i18n->get('new height description'),
-name=>"Height",
-value=>$y,
);
$f->integer(
-label=>$i18n->get('top'),
-hoverHelp=>$i18n->get('new width description'),
-name=>"Top",
-value=>$x,
);
$f->integer(
-label=>$i18n->get('left'),
-hoverHelp=>$i18n->get('new height description'),
-name=>"Left",
-value=>$y,
);
$f->submit;
my $image = '<div align="center" class="yui-skin-sam"><img src="'.$self->getStorageLocation->getUrl($filename).'" style="border-style:none;" alt="'.$filename.'" id="yui_img" /></div>'.$crop_js;
return $self->getAdminConsole->render($f->print.$image,$i18n->get("crop image"));
}
#-------------------------------------------------------------------
# Use superclass method for now.
sub www_view {

View file

@ -1054,6 +1054,78 @@ sub renameFile {
#-------------------------------------------------------------------
=head2 crop ( filename [, width, height ] )
Resizes the specified image by the specified height and width. If either is omitted the iamge will be scaleed proportionately to the non-omitted one.
=head3 filename
The name of the file to resize.
=head3 width
The new width of the image in pixels.
=head3 height
The new height of the image in pixels.
=head3 x
The top of the image in pixels.
=head3 y
The top of the image in pixels.
=cut
# TODO: Make this take a hash reference with width, height, and density keys.
sub crop {
my $self = shift;
my $filename = shift;
my $width = shift;
my $height = shift;
my $x = shift;
my $y = shift;
unless (defined $filename) {
$self->session->errorHandler->error("Can't resize when you haven't specified a file.");
return 0;
}
unless ($self->isImage($filename)) {
$self->session->errorHandler->error("Can't resize something that's not an image.");
return 0;
}
unless ($width || $height || $x || $y) {
$self->session->errorHandler->error("Can't resize with no resizing parameters.");
return 0;
}
my $image = Image::Magick->new;
my $error = $image->Read($self->getPath($filename));
if ($error) {
$self->session->errorHandler->error("Couldn't read image for resizing: ".$error);
return 0;
}
# Next, resize dimensions
if ( $width || $height || $x || $y ) {
$self->session->errorHandler->info( "Resizing $filename to w:$width h:$height x:$x y:$y" );
$image->Crop( height => $height, width => $width, x => $x, y => $y );
}
# Write our changes to disk
$error = $image->Write($self->getPath('crop-'.$filename));
if ($error) {
$self->session->errorHandler->error("Couldn't resize image: ".$error);
return 0;
}
return 1;
}
#-------------------------------------------------------------------
=head2 resize ( filename [, width, height ] )
Resizes the specified image by the specified height and width. If either is omitted the iamge will be scaleed proportionately to the non-omitted one.

View file

@ -77,6 +77,12 @@ shown here.|,
lastUpdated => 1106765841
},
'crop image' => {
message => q|Crop Image|,
context => q|label to crop the image|,
lastUpdated => 1106765841
},
'new width' => {
message => q|New Width|,
context => q|label to resize the image|,
@ -101,6 +107,30 @@ shown here.|,
lastUpdated => 1130538987
},
'height' => {
message => q|Height|,
context => q|label to resize the image|,
lastUpdated => 1106765841
},
'width' => {
message => q|Width|,
context => q|label to resize the image|,
lastUpdated => 1106765841
},
'top' => {
message => q|Top|,
context => q|label to resize the image|,
lastUpdated => 1106765841
},
'left' => {
message => q|Left|,
context => q|label to resize the image|,
lastUpdated => 1106765841
},
'image template title' => {
message => q|Image Template Variables|,
lastUpdated => 1184820779,