public
Description: my random ruby scripts
Homepage:
Clone URL: git://github.com/kastner/ruby-junk.git
Click here to lend your support to: ruby-junk and make a donation at www.pledgie.com !
ruby-junk / extract-saks.rb
100644 65 lines (50 sloc) 1.797 kb
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby
#####################################################################################
# Extract images from Saks
#
# Usage: extract-saks.rb <product-id>
#
# Requires:
# nokogiri gem
# swftools
# imagemagick (command line)
#
# Installing imagemagick (for the montage tool):
# brew install imagemagick
#
# Installing swftools (for the swfextract tool):
# brew install swftools
#####################################################################################
 
prod = ARGV[0] || "845524446172650"
 
require 'rubygems'
require 'open-uri'
require 'nokogiri'
 
def split_up(num)
  num.scan(/(..)(...)(....)/).join("/") + "/#{num}/#{num}R_Z/"
end
 
url = "http://www.saksfifthavenue.com/main/ProductDetail.jsp?PRODUCT%3C%3Eprd_id="
 
prod_image_id = open(url + prod).read[/<link rel="image_src".+?\/(\d{5,})\//, 1]
 
raise "Couldn't find product image id" unless prod_image_id
 
image_base = "http://images.saksfifthavenue.com/images/products/"
image_base << split_up(prod_image_id)
 
zoom = Nokogiri.parse(open(image_base + "/zoom.info").read)
width = zoom.at("info")["ImageWidth"].to_i
height = zoom.at("info")["ImageHeight"].to_i
tile_size = zoom.at("info")["TileSize"].to_f
 
tiles_x = (width/tile_size).ceil
tiles_y = (height/tile_size).ceil
 
# raise "across: #{tiles_x}, down: #{tiles_y} - size #{tile_size} width: #{width}"
 
tmp_path = "/tmp/imgs_for_#{prod}"
output = "#{prod}-big.jpg"
 
FileUtils.mkdir(tmp_path)
 
tiles_x.times do |x|
  tiles_y.times do |y|
    px = "%02d" % x
    py = "%02d" % y
    new_swf = "#{tmp_path}/#{py}-#{px}.swf"
    %x|curl #{image_base}Tile_00_#{px}_#{py}.swf -o #{new_swf}|
%x|swfextract #{new_swf} -j 1 -o #{new_swf}.jpg|
end
end
 
%x|montage #{tmp_path}/*.jpg -tile #{tiles_x}x#{tiles_y} -geometry -2-2 #{output}|
%x|open #{output}|