Skip to content

Commit 4bbf70f

Browse files
committed
photo.copy_to_local_file(:original) before local ImageMagick - thoughtbot/paperclip#2028
1 parent aefa0df commit 4bbf70f

File tree

4 files changed

+14
-28
lines changed

4 files changed

+14
-28
lines changed

app/assets/javascripts/analyze.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,6 @@ $W = {
290290
f.submit();
291291
},
292292

293-
set_sample_row: function() {
294-
var rownum = prompt('Enter the percentage from the top edge from which you would like to extract a spectrum.','100')
295-
$("#imagelink")[0].onclick = ""
296-
$('#imagelink').tooltip('destroy')
297-
if (rownum) window.location = '/spectrums/setsamplerow/'+$W.spectrum_id+'?row='+rownum/100.00
298-
},
299-
300293
click_to_set_sample_row: function() {
301294
$("#imagelink")[0].onclick = ""
302295
$('#imagelink').tooltip('destroy')

app/controllers/spectrums_controller.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,6 @@ def match
468468
render html: @spectrum.find_match_in_set(params[:set]).to_json
469469
end
470470

471-
# Start doing this client side!
472-
def setsamplerow
473-
require 'rubygems'
474-
require 'rmagick'
475-
@spectrum = Spectrum.find params[:id]
476-
require_ownership(@spectrum)
477-
image = Magick::ImageList.new('public' + (@spectrum.photo.url.split('?')[0]).gsub('%20', ' '))
478-
@spectrum.sample_row = (params[:row].to_f * image.rows)
479-
@spectrum.extract_data
480-
@spectrum.save
481-
flash[:warning] = "If this spectrum image is not perfectly vertical, you may need to recalibrate after <a href='//publiclab.org/wiki/spectral-workbench-calibration#Cross+section'>setting a new cross-section</a>."
482-
redirect_to spectrum_path(@spectrum)
483-
end
484-
485-
# Start doing this client side!
486471
def find_brightest_row
487472
@spectrum = Spectrum.find params[:id]
488473
require_ownership(@spectrum)

app/models/spectrum.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def self.weekly_tallies
114114

115115
# finds the brightest row of the image and uses that as its sample row
116116
def find_brightest_row
117-
image = Magick::ImageList.new('public' + (photo.url.split('?')[0]).gsub('%20', ' '))
117+
photo.copy_to_local_file(:original)
118+
image = Magick::ImageList.new(local_photo_path)
118119
brightest_row = 0
119120
brightest = 0
120121
# sum brightness for each row
@@ -140,7 +141,8 @@ def find_brightest_row
140141
def extract_data
141142
pixels = []
142143

143-
image = Magick::ImageList.new('public' + (photo.url.split('?')[0]).gsub('%20', ' '))
144+
photo.copy_to_local_file(:original)
145+
image = Magick::ImageList.new(local_photo_path)
144146
# saved sample_row may be greater than image height, so temporarily compensate,
145147
# but preserve sample_row in case we rotate back or something
146148
self.sample_row = image.rows - 2 if sample_row > image.rows
@@ -278,15 +280,17 @@ def clone_calibration(clone_id)
278280

279281
# rotate clockwise
280282
def rotate
281-
image = Magick::ImageList.new('public' + (photo.url.split('?')[0]).gsub('%20', ' '))
283+
photo.copy_to_local_file(:original)
284+
image = Magick::ImageList.new(local_photo_path)
282285
image.rotate!(-90)
283286
image.write('public' + photo.url)
284287
photo.reprocess!
285288
end
286289

287290
# horizontally flips image to match reversed spectrum, toggles 'reversed' flag
288291
def reverse
289-
image = Magick::ImageList.new('public' + (photo.url.split('?')[0]).gsub('%20', ' '))
292+
photo.copy_to_local_file(:original)
293+
image = Magick::ImageList.new(local_photo_path)
290294
image.flop!
291295
image.write('public' + photo.url)
292296
self.reversed = !reversed
@@ -629,4 +633,9 @@ def find_similar(range)
629633
def spectrum_params
630634
params.require(:spectrum).permit(:title, :author, :user_id, :notes, :photo, :video_row, :data)
631635
end
632-
end
636+
637+
def local_photo_path
638+
'public' + (photo.url.split('?')[0]).gsub('%20', ' ')
639+
end
640+
641+
end

config/routes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@
160160
get 'spectrums/rss' => 'spectrums#rss'
161161
get 'spectrums/find_brightest_row' => 'spectrums#find_brightest_row'
162162
get 'spectrums/upload' => 'spectrums#upload'
163-
get 'spectrums/setsamplerow' => 'spectrums#setsamplerow'
164163
get 'spectrums/rotate' => 'spectrums#rotate'
165164
get 'spectrums/fork' => 'spectrums#fork'
166165
get 'spectrums/reverse' => 'spectrums#reverse'

0 commit comments

Comments
 (0)