Jump to content
Wiki Home
EPrints Home
Bazaar
Files
Main menu
Main menu
move to sidebar
hide
Navigation
Front Page
EPrints 3 Manual
EPrints Training Course
EPrints Glossary
Installing EPrints
How-to Configure EPrints
EPrints 3.2+ API
EPrints 3 Reference
EPrints Plugins
Wiki
All categories
Recent changes
Main Page
Help
EPrints Documentation
Search
Search
Appearance
Log in
Request account
Personal tools
Log in
Request account
Pages for logged out editors
learn more
Contributions
Talk
Editing
How to customise thumbnails
Page
Discussion
British English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
Based on EPrints-3.3.10. To customise the size and type of thumbnails generated by eprints you can create archive-based configuration. The steps below show how to add a new thumbnail size, and render it the way *I* want it. The default thumbnails are generated by: <code>~/perl_lib/EPrints/Plugin/Convert/Thumbnails.pm</code> I wanted to add a new size 160x90px, called 'homepage' (to fit in with the institution's branding). To make your own set of thumbnail sizes, edit <code>~/archives/ARCHIVEID/cfg/cfg.d/plugins.pl</code>. I added the following to the file: <syntaxhighlight lang="perl"> $c->{plugins}->{'Convert::Thumbnails'}->{params}->{sizes} = {( small => [66,50], homepage => [160, 90], # new size - others are copied from Thumbnails.pm medium => [200,150], preview => [400,300], lightbox => [640,480], )}; $c->{thumbnail_types} = sub { my( $list, $repo, $doc ) = @_; push @$list, qw( homepage ); # add new size to list of files to be generated }; </syntaxhighlight> By default this will produce a thumbnail that will fit into a box 160x90px - a proportionally scaled down version of the original. The 'small' thumbnail size produces a cropped version of the original. This is a better option for my needs, but it has a grey 1px border around it - that I don't want. To alter the thumbnails I need to add the following to <code>~/archives/ARCHIVEID/cfg/cfg.d/plugins.pl</code> - which is a slightly modified version of the <code>sub call_convert</code> copied from Thumbnails.pl <syntaxhighlight lang="perl"> $c->{plugins}->{'Convert::Thumbnails'}->{params}->{call_convert} = sub { my( $self, $dir, $doc, $src, $geom, $size ) = @_; my $convert = $self->{'convert'}; my $version = $self->convert_version; if (!defined($geom)) { EPrints::abort("NO GEOM"); } my $fn = $size . ".jpg"; my $dst = "$dir/$fn"; $geom = "$geom->[0]x$geom->[1]"; # JPEG # Read this: http://www.imagemagick.org/script/command-line-processing.php#geometry # for details of the convert geom options. # if( $size eq "small" ) { # attempt to create a thumbnail that fits within the given dimensions # geom^ requires 6.3.8 if( $version > 6.3 ) { $self->_system($convert, "-strip", "-colorspace", "RGB", "-background", "white", "-thumbnail","$geom^", "-gravity", "center", "-extent", $geom, "-bordercolor", "gray", "-border", "1x1", $src."[0]", "JPEG:$dst"); } else { $self->_system($convert, "-strip", "-colorspace", "RGB", "-background", "white", "-thumbnail","$geom>", "-extract", $geom, "-bordercolor", "gray", "-border", "1x1", $src."[0]", "JPEG:$dst"); } } elsif( $size eq "homepage" ) # This is the new section to deal with the new 'homepage' size { # attempt to create a thumbnail that fits within the given dimensions # geom^ requires 6.3.8 if( $version > 6.3 ) { # homepage thumbnails don't want a border on them! $self->_system($convert, "-strip", "-colorspace", "RGB", "-background", "white", "-thumbnail","$geom^", "-gravity", "center", "-extent", $geom, "-bordercolor", "white", "-border", "0x0", $src."[0]", "JPEG:$dst"); } else { # homepage thumbnails don't want a border on them! $self->_system($convert, "-strip", "-colorspace", "RGB", "-background", "white", "-thumbnail","$geom>", "-extract", $geom, "-bordercolor", "white", "-border", "0x0", $src."[0]", "JPEG:$dst"); } } elsif( $size eq "medium" ) { $self->_system($convert, "-strip", "-colorspace", "RGB", "-trim", "+repage", "-size", "$geom", "-thumbnail","$geom>", "-background", "white", "-gravity", "center", "-extent", $geom, "-bordercolor", "white", "-border", "0x0", $src."[0]", "JPEG:$dst"); } else { $self->_system($convert, "-strip", "-colorspace", "RGB", "-background", "white", "-thumbnail","$geom>", "-extract", $geom, "-bordercolor", "white", "-border", "0x0", $src."[0]", "JPEG:$dst"); } if( -s $dst ) { return ($fn); } return (); }; </syntaxhighlight> To test the new thumbnail generation, find an eprint with some good images attached to it. In the example below I'll use '1234', and assume the original image is called 'file.jpg' and is the first document in the eprint (this only matters for the URL to view the image in the browser with). Run <code>~/bin/epadmin redo_thumbnails ARCHIVEID 1234 --verbose</code> You should see the convert command being run - and the new size filename being created e.g. <syntaxhighlight lang="bash"> Starting EPrints Repository. Connecting to DB ... done. Redoing thumbnails for document 1234 /usr/bin/convert -strip -colorspace RGB -background white -thumbnail 160x90^ -gravity center -extent 160x90 -bordercolor white -border 0x0 /opt/eprints3/archives/digitallibrary/documents/disk0/00/00/12/34/01/file.jpg[0] JPEG:/tmp/_NyUoqmsuZ/homepage.jpg /usr/bin/convert ... JPEG:/tmp/XR51ieKBCj/lightbox.jpg /usr/bin/convert ... JPEG:/tmp/fCOP2BPoa2/preview.jpg /usr/bin/convert ... JPEG:/tmp/zLEip1ewUq/medium.jpg /usr/bin/convert ... JPEG:/tmp/weRJwQPgNT/small.jpg </syntaxhighlight> NB The lines for lightbox, preview, medium and small.jpg have been truncated for clarity. You should now be able to view the new thumbnails in a browser: <code><nowiki>http://your.repo.url/1234/1.hashomepageThumbnailVersion/file.jpg</nowiki></code> [[Category:Howto]][[Category:Snippets]][[Category:Contribute]]
Summary:
Please note that all contributions to EPrints Documentation may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
EPrints Documentation:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)