kastner (owner)

Revisions

gist: 213738 Download_button fork
public
Public Clone URL: git://gist.github.com/213738.git
Embed All Files: show embed
sacks-extract.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
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
#!/usr/bin/env ruby
#####################################################################################
# Extract images from Saks
#
# Requires:
# nokogiri gem
# swftools
# imagemagick (command line)
#
# Change the prod variable and run
#
#####################################################################################
 
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}|