-
Notifications
You must be signed in to change notification settings - Fork 36
Images
Breedbase has a centralized system for dealing with all images that are being stored with different object types.
Image files in Breedbase are stored in the filesystem, with metadata about the image being stored in the database, in the table metadata.md_image
. Files are stored in the directory in the config variable image_path
(accessible with $c->config->{image_path}
) and are available at the url at given by the config variable image_dir
.
The image object CXGN::Image
in the sgn
repo handles all the image related activities, such as storing a new image, retrieving an image, and changing image metadata.
All images are imported using the process_image
function in CXGN::Image
, which does the following:
- generates a temp directory using
File::Temp
in theimage_path
- generates 4 image sizes all in the
png
format (thumbnail, small, medium and large, in addition to the original file) usingimagemagick
- moves the temp_dir to a directory in the file system at the image path, plus the path generated by
image_subpath
inCXGN::Image
. (image_subpath
essentially takes the md5 checksum of the original image, and splits off 4 nested directories from the first 4 pairs of characters, and an additional nested subdirectory from the rest of the 24 characters) - The md5 checksum and other metadata, such as description, are stored in the database. The md5checksum is stored in the
md5sum
field ofmetadata.md_image
table.
Note that if the same image is uploaded twice, it will not be stored twice in the filesystem, but have two entries in the database.
The database image object can be linked to various other data objects in the database through linking tables, such as to stocks (phenome.stock_image
), organisms (metadata.md_image_organism
), cvterms (metadata.md_image_cvterm
), or tags (metadata.md_image_tags
).
The web interface is implemented via the controllers SGN::Controller::Image
and SGN::Controller::AJAX::Image
, with associated mason components in /image/
in the mason directory.
Images can be viewed at the URL /image/view/<image_id>
.
The page displays the following information:
- different recalculated image sizes
- image name, description, upload user
- associated tags
- associated database objects (such as stocks)
- an optional copyright notice
Images can be uploaded by users with submitter
privileges. The upload is a two stage process; first the user locates the image on the local storage, clicks upload, and can then view the image as uploaded. If it is ok, the user can click "Store" to store the image in the database.
The image upload is at the url /image/add
. The page requires a parameter of the object that should be linked to the image, using the parameters type
and type_id
. type
can be stock, organism or other database type. These parameters are required.
The mason component /image/embed_image.mas
can display images right from the database. The parameters are dbh
(a database handle), image_id
(the database id of the image to be displayed) and size
, the size of the image (either thumbnail, small, medium or large).
<& /image/embed_image.mas, dbh => $dbh, image_id => $image_id, size => 'medium' &>
imagemagick