Use "display" width in HTML image links

private-asciicasts
Marcin Kulik 9 years ago
parent bb622d670e
commit 7a321bf2cc

@ -33,6 +33,7 @@ gem 'rack-rewrite', '~> 1.5.0'
gem 'oj', '~> 2.11'
gem 'oj_mimic_json', '~> 1.0'
gem 'foreigner', '~> 1.7'
gem 'chunky_png', '~> 1.3'
group :development do
gem 'quiet_assets', '~> 1.0.1'
@ -64,7 +65,6 @@ group :test do
gem 'shoulda-matchers'
gem 'coveralls', require: false
gem 'rspec-activemodel-mocks'
gem 'chunky_png'
end
group :production do

@ -350,7 +350,7 @@ DEPENDENCIES
capistrano-ext (~> 1.2)
capybara (~> 2.4.1)
carrierwave (~> 0.8.0)
chunky_png
chunky_png (~> 1.3)
coffee-rails (~> 4.0.1)
coveralls
dalli (~> 2.6.2)

@ -94,7 +94,7 @@ class Asciicast < ActiveRecord::Base
end
def image_hash
version = 1 # version of screenshot, increment to force regeneration
version = 2 # version of screenshot, increment to force regeneration
input = "#{version}/#{id}/#{snapshot_at}"
Digest::SHA1.hexdigest(input)
end

@ -58,7 +58,7 @@ class AsciicastPagePresenter
def embed_html_link(routes)
img_src = routes.asciicast_url(asciicast, format: :png)
url = routes.asciicast_url(asciicast)
%(<a href="#{url}"><img src="#{img_src}"/></a>)
%(<a href="#{url}"><img src="#{img_src}" width="#{asciicast.image_width}" /></a>)
end
def embed_markdown_link(routes)

@ -16,6 +16,11 @@ class AsciicastImageUpdater
asciicast.image = f
end
image = ChunkyPNG::Image.from_file(png_path)
# image has double density so "display" size is half the actual one
asciicast.image_width = image.width / 2
asciicast.image_height = image.height / 2
asciicast.save!
end
end

@ -0,0 +1,6 @@
class AddImageWidthAndHeightToAsciicasts < ActiveRecord::Migration
def change
add_column :asciicasts, :image_width, :integer
add_column :asciicasts, :image_height, :integer
end
end

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150324103607) do
ActiveRecord::Schema.define(version: 20150327171201) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -56,6 +56,8 @@ ActiveRecord::Schema.define(version: 20150324103607) do
t.integer "version", null: false
t.string "file"
t.string "image"
t.integer "image_width"
t.integer "image_height"
end
add_index "asciicasts", ["created_at"], name: "index_asciicasts_on_created_at", using: :btree

Loading…
Cancel
Save