diff options
author | Dave Arter <davea@mysociety.org> | 2018-09-19 17:40:07 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2018-09-28 16:19:47 +0100 |
commit | 64cb4e23433b9fb7862f763e1819b6ac3318c3e6 (patch) | |
tree | 72fcad96068a4997fa23a670c6ec97d393334302 /perllib/FixMyStreet/PhotoStorage.pm | |
parent | ec55469dadd99dd0f20d3d0c3b4202b6b70bb6ab (diff) |
Factor out photo storage into PhotoStorage::FileSystem backend
Diffstat (limited to 'perllib/FixMyStreet/PhotoStorage.pm')
-rw-r--r-- | perllib/FixMyStreet/PhotoStorage.pm | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/PhotoStorage.pm b/perllib/FixMyStreet/PhotoStorage.pm new file mode 100644 index 000000000..99f0bdab6 --- /dev/null +++ b/perllib/FixMyStreet/PhotoStorage.pm @@ -0,0 +1,30 @@ +package FixMyStreet::PhotoStorage; + +use Moose; +use Digest::SHA qw(sha1_hex); + + +sub detect_type { + my ($self, $photo) = @_; + return 'jpeg' if $photo =~ /^\x{ff}\x{d8}/; + return 'png' if $photo =~ /^\x{89}\x{50}/; + return 'tiff' if $photo =~ /^II/; + return 'gif' if $photo =~ /^GIF/; + return ''; +} + +=head2 get_fileid + +Calculates an identifier for a binary blob of photo data. +This is just the SHA1 hash of the blob currently. + +=cut + +sub get_fileid { + my ($self, $photo_blob) = @_; + return sha1_hex($photo_blob); +} + + + +1; |