image_suckr 0.0.3 → 0.0.4
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.
- data/README.md +31 -9
- data/lib/image_suckr/version.rb +1 -1
- data/lib/image_suckr.rb +2 -2
- metadata +1 -1
data/README.md
CHANGED
@@ -1,27 +1,49 @@
|
|
1
1
|
Description
|
2
|
-
|
2
|
+
---
|
3
3
|
ImageSuckr is a ruby gem that allows you to get random images from Google for seeding purposes.
|
4
|
+
|
4
5
|
In a future it will support other sources.
|
5
6
|
|
6
7
|
Installation
|
7
|
-
|
8
|
+
---
|
8
9
|
1. Add `gem 'image_suckr'` to your Gemfile
|
9
10
|
2. Run `bundle install`
|
10
11
|
|
11
12
|
Basic use
|
12
|
-
|
13
|
+
---
|
14
|
+
**Create an ImageSuckr object:**
|
15
|
+
|
13
16
|
suckr = ImageSuckr::GoogleSuckr.new
|
14
17
|
|
15
|
-
To get a fully random image
|
18
|
+
**To get a fully random image URL:**
|
16
19
|
|
17
|
-
suckr.
|
20
|
+
suckr.get_image_url
|
18
21
|
|
19
|
-
To get a random image
|
22
|
+
**To get a random image URL based on a query:**
|
20
23
|
|
21
|
-
suckr.
|
24
|
+
suckr.get_image_url({"q" => "car"})
|
22
25
|
|
23
26
|
_All [Google Image Search API arguments](http://code.google.com/apis/imagesearch/v1/jsondevguide.html#json_args) are supported and you can use them to filter your results._
|
24
27
|
|
25
|
-
To get the image content instead of the
|
28
|
+
**To get the image content instead of the URL:**
|
29
|
+
|
30
|
+
suckr.get_image
|
31
|
+
|
32
|
+
Other useful examples
|
33
|
+
---
|
34
|
+
|
35
|
+
**To get a RMagick image:**
|
36
|
+
|
37
|
+
_You need to install [RMagick](http://rmagick.rubyforge.org/) to use this._
|
26
38
|
|
27
|
-
suckr.
|
39
|
+
image = Magick::Image.from_blob(suckr.get_image).first
|
40
|
+
|
41
|
+
**To get a MiniMagick image:**
|
42
|
+
|
43
|
+
_You need to install [MiniMagick](https://github.com/probablycorey/mini_magick) to use this._
|
44
|
+
|
45
|
+
image = MiniMagick::Image.read(suckr.get_image)
|
46
|
+
|
47
|
+
or
|
48
|
+
|
49
|
+
image = MiniMagick::Image.open(suckr.get_image_url)
|
data/lib/image_suckr/version.rb
CHANGED
data/lib/image_suckr.rb
CHANGED
@@ -16,7 +16,7 @@ module ImageSuckr
|
|
16
16
|
"v" => "1.0"
|
17
17
|
}
|
18
18
|
|
19
|
-
def
|
19
|
+
def get_image_url(params = {})
|
20
20
|
params = DEFAULT_PARAMS.merge(params)
|
21
21
|
params["q"] = rand(1000).to_s if params["q"].nil?
|
22
22
|
url = "http://ajax.googleapis.com/ajax/services/search/images?" + params.to_query
|
@@ -25,7 +25,7 @@ module ImageSuckr
|
|
25
25
|
imageUrl = result["responseData"]["results"][rand(params["rsz"].to_i)]["url"]
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def get_image(params = {})
|
29
29
|
image = Net::HTTP.get_response(URI.parse(getImageUrl(params))).body
|
30
30
|
end
|
31
31
|
|