forked from atom/flight-manual.atom.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrush.rb
executable file
·29 lines (26 loc) · 856 Bytes
/
crush.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#! /usr/bin/env ruby
require 'rubygems'
require 'oily_png'
Dir.glob("book/**/*.png").each do |file|
puts file
image = ChunkyPNG::Image.from_file(file)
p image.width
p image.height
if image.width > 800 || image.height > 800
if image.width > image.height
`convert -resize 800x #{file} #{file}.smaller.png`
else
`convert -resize x800 #{file} #{file}.smaller.png`
end
`pngcrush #{file}.smaller.png #{file}`
`rm #{file}.smaller.png`
end
end
# [2,0.5].each do |scale|
# resized_image = ChunkyPNG::Image.new((image.width * scale).round, (image.height * scale).round)
# resized_image.pixels.map!.with_index do |pixel, index|
# x, y = index % resized_image.width, (index / resized_image.width).floor
# image[x / scale, y / scale]
# end
# resized_image.save("bassie_resized_#{scale}.png")
# end