catscope 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ada87ae81e6ac66cd788f826d5dd009091cd99d
4
- data.tar.gz: ada37681655fbbc19e48f0263a6a78bfee521607
3
+ metadata.gz: a04352dbd5d2bc81dbceed21903c1bd5e0096e5c
4
+ data.tar.gz: 01e87cf27af948d71f8a440e03785c90959934dc
5
5
  SHA512:
6
- metadata.gz: e5b02ea67ee0ca6994ae3541a66a1062da7b98088764cb997e716040f1f776db44db1df1567d91278650eb55c1cb0e90441053ba44f305e3671da7f8ed4a05d4
7
- data.tar.gz: 7b4a8bb095131e62f2e4d741f8e5b5eca3068beff2c9d4e67f9a977050798d4afa1688f6ef1f19d62ddcdebf92480896804cd79c58225823b3f4709fdfdba928
6
+ metadata.gz: 3b1b3b97e558c044a43feab5d1f2f9e453352dd8b4c3119fd526e23ce7ee520ad21d6799acb5aa7a0a97290b4f29b6c9d853e58c978f291f02c312b624fc973c
7
+ data.tar.gz: 05dd7cf692a3331a8a23d7a7533106c303385505bc5b9572f60b108eda72b7265b04c33ffca3c9c1e0137e4b02984a9a5ac07f4c04d11955a4ad4db94154f600
data/lib/catscope/app.rb CHANGED
@@ -9,7 +9,9 @@ require 'json'
9
9
  module Catscope
10
10
 
11
11
  class App < Sinatra::Base
12
+ EPS_MIN_PIXELS = 1024*1024 / 2
12
13
  TOP_DIR = Pathname.new(Dir.pwd).realpath
14
+
13
15
  register Sinatra::AssetPack
14
16
  register Sinatra::RocketIO
15
17
 
@@ -60,6 +62,18 @@ class App < Sinatra::Base
60
62
  return "text/plain"
61
63
  end
62
64
  end
65
+
66
+ def image_size(file_path)
67
+ unless system("which identify >/dev/null 2>&1")
68
+ return nil
69
+ end
70
+
71
+ identify_str = `identify "#{file_path}"`
72
+ unless identify_str =~ /\s(\d+)x(\d+)\s/
73
+ return nil
74
+ end
75
+ [$~[1].to_i, $~[2].to_i]
76
+ end
63
77
  end
64
78
 
65
79
  io = Sinatra::RocketIO
@@ -128,8 +142,19 @@ class App < Sinatra::Base
128
142
  content_type type_by_path(path)
129
143
 
130
144
  if path =~ /\.(eps|svg)$/
131
- out = IO.popen("convert \"#{path}\" png:-")
132
- puts("convert #{path} to png")
145
+ imgsize = image_size(path)
146
+
147
+ p imgsize
148
+
149
+ resize_option = ""
150
+ if imgsize && imgsize[0]*imgsize[1] < EPS_MIN_PIXELS
151
+ dpi = (72 * ((EPS_MIN_PIXELS / (imgsize[0]*imgsize[1]).to_f)) ** 0.5).to_i
152
+ resize_option = "-density #{dpi}"
153
+ end
154
+
155
+ convert_cmd = "convert #{resize_option} \"#{path}\" png:-"
156
+ out = IO.popen(convert_cmd)
157
+ puts(convert_cmd)
133
158
  else
134
159
  out = File.open(path)
135
160
  end
@@ -1,3 +1,3 @@
1
1
  module Catscope
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuto Hayamizu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-09 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thin