Class: Imageproxy::Selftest

Inherits:
Object
  • Object
show all
Defined in:
lib/imageproxy/selftest.rb

Class Method Summary collapse

Class Method Details

.html(request, signature_required, signature_secret) ⇒ Object



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
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/imageproxy/selftest.rb', line 3

def self.html(request, signature_required, signature_secret)
  html = "  <html>\n    <head>\n      <title>imageproxy selftest</title>\n      <style type=\"text/css\">\n        body { background: url(/background.png); font-family: \"Helvetica\", sans-serif; font-size: smaller; }\n        h3 { margin: 2em 0 0 0; }\n        img { display: block; border: 1px solid black; margin: 1em 0; }\n        .footer { margin-top: 2em; border-top: 1px solid #999; padding-top: 0.5em; font-size: smallest; }\n      </style>\n    </head>\n    <body>\n  HTML\n\n  url_prefix = \"\#{request.scheme}://\#{request.host_with_port}\"\n  raw_source = \"http://eahanson.s3.amazonaws.com/imageproxy/sample.png\"\n  source = CGI.escape(URI.escape(URI.escape(raw_source)))\n\n  raw_overlay = \"http://www.imagemagick.org/image/smile.gif\"\n  overlay = CGI.escape(URI.escape(URI.escape(raw_overlay)))\n\n  html += <<-HTML\n  <h3>Original Image</h3>\n  <a href=\"\#{raw_source}\">\#{raw_source}</a>\n  <img src=\"\#{raw_source}\">\n  HTML\n\n  examples = [\n    [\"Resize (regular query-string URL format)\", \"/convert?resize=100x100&source=\#{source}\"],\n    [\"Resize (CloudFront-compatible URL format)\", \"/convert/resize/100x100/source/\#{source}\"],\n\n    [\"Resize with padding\", \"/convert?resize=100x100&shape=pad&source=\#{source}\"],\n    [\"Resize with padding & background color\", \"/convert?resize=100x100&shape=pad&background=%23ff00ff&source=\#{source}\"],\n\n    [\"Resize with cutting\", \"/convert?resize=100x100&shape=cut&source=\#{source}\"],\n\n    [\"Flipping horizontally\", \"/convert?flip=horizontal&source=\#{source}\"],\n    [\"Flipping vertically\", \"/convert?flip=vertical&source=\#{source}\"],\n\n    [\"Rotating to a 90-degree increment\", \"/convert?rotate=90&source=\#{source}\"],\n    [\"Rotating to a non-90-degree increment\", \"/convert?rotate=120&source=\#{source}\"],\n    [\"Rotating to a non-90-degree increment with a background color\", \"/convert?rotate=120&background=%23ff00ff&source=\#{source}\"],\n\n    [\"Combo\", \"/convert?resize=100x100&shape=cut&rotate=45&background=%23ff00ff&source=\#{source}\"],\n\n    [\"Compositing\", \"/convert?source=\#{source}&overlay=\#{overlay}\"],\n    [\"Composite and then do something else\", \"/convert?source=\#{source}&overlay=\#{overlay}&rotate=50\"]\n  ]\n\n  examples.each do |example|\n    path = example[1]\n    if (signature_required)\n      signature = CGI.escape(Signature.create(path, signature_secret))\n      if path.include?(\"&\")\n        path += \"&signature=\#{signature}\"\n      else\n        path += \"/signature/\#{signature}\"\n      end\n    end\n    example_url = url_prefix + path\n    html += <<-HTML\n    <h3>\#{example[0]}</h3>\n    <a href=\"\#{example_url}\">\#{example_url}</a>\n    <img src=\"\#{example_url}\">\n    HTML\n  end\n\n  html += <<-HTML\n      <div class=\"footer\"><a href=\"https://github.com/eahanson/imageproxy\">imageproxy</a> selftest</div>\n    </body>\n  </html>\n  HTML\n\n  html\nend\n"