Skip to content

Commit

Permalink
photo.copy_to_local_file(:original) before local ImageMagick - though…
Browse files Browse the repository at this point in the history
  • Loading branch information
jywarren committed Jan 25, 2022
1 parent aefa0df commit 4bbf70f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
7 changes: 0 additions & 7 deletions app/assets/javascripts/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,6 @@ $W = {
f.submit();
},

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

click_to_set_sample_row: function() {
$("#imagelink")[0].onclick = ""
$('#imagelink').tooltip('destroy')
Expand Down
15 changes: 0 additions & 15 deletions app/controllers/spectrums_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -468,21 +468,6 @@ def match
render html: @spectrum.find_match_in_set(params[:set]).to_json
end

# Start doing this client side!
def setsamplerow
require 'rubygems'
require 'rmagick'
@spectrum = Spectrum.find params[:id]
require_ownership(@spectrum)
image = Magick::ImageList.new('public' + (@spectrum.photo.url.split('?')[0]).gsub('%20', ' '))
@spectrum.sample_row = (params[:row].to_f * image.rows)
@spectrum.extract_data
@spectrum.save
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>."
redirect_to spectrum_path(@spectrum)
end

# Start doing this client side!
def find_brightest_row
@spectrum = Spectrum.find params[:id]
require_ownership(@spectrum)
Expand Down
19 changes: 14 additions & 5 deletions app/models/spectrum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def self.weekly_tallies

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

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

# rotate clockwise
def rotate
image = Magick::ImageList.new('public' + (photo.url.split('?')[0]).gsub('%20', ' '))
photo.copy_to_local_file(:original)
image = Magick::ImageList.new(local_photo_path)
image.rotate!(-90)
image.write('public' + photo.url)
photo.reprocess!
end

# horizontally flips image to match reversed spectrum, toggles 'reversed' flag
def reverse
image = Magick::ImageList.new('public' + (photo.url.split('?')[0]).gsub('%20', ' '))
photo.copy_to_local_file(:original)
image = Magick::ImageList.new(local_photo_path)
image.flop!
image.write('public' + photo.url)
self.reversed = !reversed
Expand Down Expand Up @@ -629,4 +633,9 @@ def find_similar(range)
def spectrum_params
params.require(:spectrum).permit(:title, :author, :user_id, :notes, :photo, :video_row, :data)
end
end

def local_photo_path
'public' + (photo.url.split('?')[0]).gsub('%20', ' ')
end

end
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
get 'spectrums/rss' => 'spectrums#rss'
get 'spectrums/find_brightest_row' => 'spectrums#find_brightest_row'
get 'spectrums/upload' => 'spectrums#upload'
get 'spectrums/setsamplerow' => 'spectrums#setsamplerow'
get 'spectrums/rotate' => 'spectrums#rotate'
get 'spectrums/fork' => 'spectrums#fork'
get 'spectrums/reverse' => 'spectrums#reverse'
Expand Down

0 comments on commit 4bbf70f

Please sign in to comment.