Skip to content

Commit

Permalink
Merge pull request #204 from robotmay/master
Browse files Browse the repository at this point in the history
Bugfixes for image processing issues
  • Loading branch information
robotmay committed Nov 18, 2013
2 parents d04efca + 60ded33 commit 9025c39
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ GEM
metaclass (0.0.1)
method_source (0.8.1)
mime-types (1.25)
mini_exiftool (1.6.0)
mini_exiftool (2.3.0)
mini_exiftool_vendored (8.9.7.v2)
mini_exiftool (>= 1.6.0)
minitest (4.7.5)
Expand Down
2 changes: 2 additions & 0 deletions app/models/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ def fetch_from_exif(exif, keys = [])
return_hash = {}

exif.to_hash.each do |key, value|
next if key.nil?

key = key.underscore.to_sym
if keys.include?(key)
return_hash[key] = value
Expand Down
2 changes: 1 addition & 1 deletion app/models/photograph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def visible?

def exif
Photograph.benchmark "Parsing image for EXIF" do
MiniExiftool.new(image.file.path)
MiniExiftool.new(image.file.path, replace_invalid_chars: '')
end
end

Expand Down
28 changes: 20 additions & 8 deletions app/workers/photo_expansion_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ class MetadataRecordMissing < StandardError; end
sidekiq_options queue: :photos

def perform(photograph_id)
timeout(300) do
@photo = Photograph.find(photograph_id)
begin
timeout(300) do
@photo = Photograph.find(photograph_id)

# Extract the metadata and save it
extract_metadata
# Extract the metadata and save it
extract_metadata

# Generate all the other image sizes
generate_images
# Generate all the other image sizes
generate_images

@photo.save!
@photo.save!
end
rescue Exception => ex
if @photo.present?
@photo.logs << [ex.message, "\n", ex.backtrace.take(5).join("\n")]
end

raise ex
end
end

Expand All @@ -38,7 +46,11 @@ def extract_metadata
metadata.extract_from_photograph

@photo.logs << "Saving metadata record"
metadata.save!
if metadata.save!
@photo.logs << "Metadata record saved"
else
@photo.logs << "Metadata didn't save successfully"
end
end
end

Expand Down
5 changes: 4 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
config.cache_classes = true

# Other caching configuration
config.cache_store = :dalli_store
config.cache_store = :dalli_store, {
value_max_bytes: 10.megabytes,
compress: true
}
config.action_controller.perform_caching = true
config.action_dispatch.rack_cache = {
metastore: Dalli::Client.new,
Expand Down
11 changes: 11 additions & 0 deletions spec/models/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@
wibble_pt: 100
})
end

context "nil keys" do
let(:exif) { { nil => nil, "test" => 100 } }

it "returns an underscore-keyed array without the nil keys" do
hash = metadata.send(:fetch_from_exif, exif, [:test])
hash.should eq({
test: 100
})
end
end
end

describe "#rotate?" do
Expand Down

0 comments on commit 9025c39

Please sign in to comment.