appengine-apis 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +202 -0
- data/README.rdoc +3 -5
- data/Rakefile +45 -22
- data/lib/appengine-apis.rb +1 -1
- data/lib/appengine-apis/images.rb +236 -0
- data/lib/imagescience.rb +85 -0
- metadata +30 -69
- data/History.txt +0 -13
- data/Manifest.txt +0 -35
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/spec.opts +0 -1
- data/tasks/rspec.rake +0 -21
data/COPYING
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.rdoc
CHANGED
@@ -6,13 +6,11 @@
|
|
6
6
|
|
7
7
|
APIs and utilities for using JRuby on Google App Engine.
|
8
8
|
|
9
|
-
To load the API stubs in IRB simply
|
10
|
-
require 'rubygems'
|
11
|
-
require 'appengine-apis/local_boot'
|
9
|
+
To load the API stubs in IRB simply run `appcfg.rb run -S irb`.
|
12
10
|
|
13
11
|
This will configure access to the same Datastore as running
|
14
12
|
|
15
|
-
$ dev_appserver.
|
13
|
+
$ dev_appserver.rb .
|
16
14
|
|
17
15
|
See these classes for an overview of each API:
|
18
16
|
- AppEngine::Logger
|
@@ -25,7 +23,7 @@ See these classes for an overview of each API:
|
|
25
23
|
- AppEngine::XMPP
|
26
24
|
- AppEngine::Labs::TaskQueue
|
27
25
|
|
28
|
-
Unless you're implementing
|
26
|
+
Unless you're implementing an ORM, you probably want to use the
|
29
27
|
DataMapper API instead of the lower level AppEngine::Datastore API.
|
30
28
|
|
31
29
|
== REQUIREMENTS:
|
data/Rakefile
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rubygems/specification'
|
5
|
+
require 'date'
|
6
|
+
require 'spec/rake/spectask'
|
7
|
+
|
2
8
|
require File.dirname(__FILE__) + '/lib/appengine-apis'
|
3
9
|
|
4
10
|
# set up pretty rdoc if possible
|
@@ -9,28 +15,45 @@ begin
|
|
9
15
|
rescue Exception
|
10
16
|
end
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
GEM = "appengine-apis"
|
19
|
+
GEM_VERSION = AppEngine::VERSION
|
20
|
+
AUTHOR = "Ryan Brown"
|
21
|
+
EMAIL = "ribrdb@gmail.com"
|
22
|
+
HOMEPAGE = "http://code.google.com/p/appengine-jruby"
|
23
|
+
SUMMARY = "Ruby API wrappers for App Engine"
|
24
|
+
|
25
|
+
spec = Gem::Specification.new do |s|
|
26
|
+
s.name = GEM
|
27
|
+
s.version = GEM_VERSION
|
28
|
+
s.platform = Gem::Platform::RUBY
|
29
|
+
s.has_rdoc = true
|
30
|
+
s.extra_rdoc_files = ["README.rdoc", "COPYING"]
|
31
|
+
s.summary = SUMMARY
|
32
|
+
s.description = s.summary
|
33
|
+
s.author = AUTHOR
|
34
|
+
s.email = EMAIL
|
35
|
+
s.homepage = HOMEPAGE
|
25
36
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
s.add_dependency("appengine-rack")
|
38
|
+
|
39
|
+
s.require_path = 'lib'
|
40
|
+
s.files = %w(COPYING README.rdoc Rakefile) + Dir.glob("{lib,spec}/**/*.rb")
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
desc "Run specs"
|
46
|
+
Spec::Rake::SpecTask.new do |t|
|
47
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
48
|
+
t.spec_opts = %w(-fs --color)
|
30
49
|
end
|
31
50
|
|
32
|
-
require 'newgem/tasks' # load /tasks/*.rake
|
33
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
34
51
|
|
35
|
-
|
36
|
-
|
52
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
53
|
+
pkg.gem_spec = spec
|
54
|
+
end
|
55
|
+
|
56
|
+
Rake::RDocTask.new do |rd|
|
57
|
+
rd.main = "README.rdoc"
|
58
|
+
rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
|
59
|
+
end
|
data/lib/appengine-apis.rb
CHANGED
@@ -0,0 +1,236 @@
|
|
1
|
+
#!/usr/bin/ruby1.8 -w
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright 2009 Bas Wilbers
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'java'
|
18
|
+
|
19
|
+
module AppEngine
|
20
|
+
|
21
|
+
# = Image Manipulation on Google app Engine
|
22
|
+
#
|
23
|
+
# == Usage
|
24
|
+
# Use it like this:
|
25
|
+
# require 'appengine-apis/images'
|
26
|
+
# image = AppEngine::Images.open('public/clown.jpg')
|
27
|
+
# image.resize(100,100)
|
28
|
+
# image.to_s #or @image.data
|
29
|
+
# # => "data string"
|
30
|
+
#
|
31
|
+
# You can also make a new Image object by simply passing a data string
|
32
|
+
# @image = AppEngine::Images.load("data string")
|
33
|
+
#
|
34
|
+
# Currently all of Google's image manipulation methods except for
|
35
|
+
# composite images. This means you can rotate, resize, crop and flip
|
36
|
+
# your images. The syntax for this is really straigthforward
|
37
|
+
#
|
38
|
+
# image = AppEngine::Images.load("data string")
|
39
|
+
# image.resize(width,height)
|
40
|
+
# image.resize!(width,height)
|
41
|
+
#
|
42
|
+
# image.rotate(angle)
|
43
|
+
# image.rotate!(angle)
|
44
|
+
#
|
45
|
+
# image.flip #flips horizontal
|
46
|
+
# image.flip(:horizontal) #default
|
47
|
+
# image.flip(:vertical)
|
48
|
+
#
|
49
|
+
# image.flip!(direction)
|
50
|
+
#
|
51
|
+
# image.crop(leftX,topY,rightX,bottomY)
|
52
|
+
# image.crop!(leftX,topY,rightX,bottomY)
|
53
|
+
#
|
54
|
+
# #Bonus method from google that tries to enhance colour
|
55
|
+
# image.i_feel_lucky
|
56
|
+
# image.i_feel_lucky!
|
57
|
+
#
|
58
|
+
# The power lies in chaining the methods:
|
59
|
+
# AppEngine::Images.open('public/clown.jpg').resize(100, 100).rotate(90).flip.to_s
|
60
|
+
#
|
61
|
+
# == Legacy
|
62
|
+
#
|
63
|
+
# Maby you feel that learning yet another image manipulation syntax is
|
64
|
+
# cumbersome. I can hardly imagine that because syntax is really
|
65
|
+
# simple. Anyway, people have numerous reasons to stick to old
|
66
|
+
# syntaxes. The most compelling argument is not having to rewrite code
|
67
|
+
# for something like GAE. The easier it is for people to port their
|
68
|
+
# app to GAE the more usefull it will be. That is why I also included
|
69
|
+
# a simple drop-in interface for ImageScience
|
70
|
+
#
|
71
|
+
# require 'imagescience.rb'
|
72
|
+
#
|
73
|
+
# ImageScience.with_image('public/clown.jpg') do |img|
|
74
|
+
# img.cropped_thumbnail(100) do |thumb|
|
75
|
+
# return thumb.to_s
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# All the methods of ImageScience are supported. It should behave
|
80
|
+
# exactly like ImageScience does. There is however one slight
|
81
|
+
# problem. Google App Engine apps cannot write files to the
|
82
|
+
# filesytem. This means that the following will never work.
|
83
|
+
#
|
84
|
+
# ImageScience.with_image('public/clown.jpg') do |img|
|
85
|
+
# img.cropped_thumbnail(100) do |thumb|
|
86
|
+
# thumb.save('public/clown_thumb.jpg')
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# To overcome this I simply added a .to_s method that returns the
|
91
|
+
# image data as a String. You can then either directly return this
|
92
|
+
# data, memcache it or store it through google DataStore.
|
93
|
+
#
|
94
|
+
# I understand that this still means you have to modify code. If you
|
95
|
+
# still want minimal effort porting your code I suggest you
|
96
|
+
# monkeypatch the class and add save yourself. Then you can store it
|
97
|
+
# the way you want(probably DataStore).
|
98
|
+
#
|
99
|
+
# But both of these approaches leave you with a problem if you want
|
100
|
+
# manipulate an image that you didn't include with your deploy. For
|
101
|
+
# example a user uploaded image or a previously modified image. You
|
102
|
+
# cannot simply write it to a tempfile and then open them with
|
103
|
+
# ImageScience.with_image. To overcome this problem I added a simple
|
104
|
+
# with_image variation called with_image_data. You just use it like
|
105
|
+
# this:
|
106
|
+
#
|
107
|
+
# ImageScience.with_image('public/clown.jpg') do |img|
|
108
|
+
# @datastring = img.to_s
|
109
|
+
# end
|
110
|
+
# #Or get your @datastring from DataStore, Memcache or post/put params
|
111
|
+
# ImageScience.with_image_data(@datastring) do |img|
|
112
|
+
# img.cropped_thumbnail(100) do |thumb|
|
113
|
+
# thumb.to_s
|
114
|
+
# # => Jeeh, another datastring let's store it safely!
|
115
|
+
# end
|
116
|
+
# end
|
117
|
+
#
|
118
|
+
# I realize this still means you need you sometimes have to do quite a
|
119
|
+
# lot of work to make it work. I personally think this is not a big
|
120
|
+
# problem as it gives your app quite some advantages. For example it
|
121
|
+
# becomes much easier to scale to app(That is the actual reason why
|
122
|
+
# you cannot write to filesystem). If you wanted to scale your app
|
123
|
+
# with amazon for example you also need to modify your code cause you
|
124
|
+
# probably want to send your images to S3.
|
125
|
+
#
|
126
|
+
# If you still feel that modifying your code is to much of a trouble
|
127
|
+
# perhaps the google app engine is just nothing for you. But ofcourse
|
128
|
+
# you can also MonkeyPatch ruby File class and use Datastore as a
|
129
|
+
# virtual filesystem. That would be quite a cool project, you can let
|
130
|
+
# File.open search the datastore first and then the read-only harddisk
|
131
|
+
# (to simulate file overwriting) You can Cache things with memcache(If
|
132
|
+
# that makes it faster). When you are done drop me a note will you?
|
133
|
+
#
|
134
|
+
# == Meta
|
135
|
+
#
|
136
|
+
# Created by Bas Wilbers
|
137
|
+
module Images
|
138
|
+
module IS
|
139
|
+
import com.google.appengine.api.images.Image
|
140
|
+
import com.google.appengine.api.images.ImagesService
|
141
|
+
import com.google.appengine.api.images.ImagesServiceFactory
|
142
|
+
import com.google.appengine.api.images.Transform
|
143
|
+
|
144
|
+
Service = ImagesServiceFactory.images_service
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.open(filename)
|
148
|
+
Image.open(filename)
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.load(data)
|
152
|
+
Image.new(data)
|
153
|
+
end
|
154
|
+
|
155
|
+
class Image
|
156
|
+
def self.open(filename)
|
157
|
+
File.open(filename) do |file|
|
158
|
+
return new(file.read)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def height
|
163
|
+
@image.getHeight
|
164
|
+
end
|
165
|
+
|
166
|
+
def width
|
167
|
+
@image.getWidth
|
168
|
+
end
|
169
|
+
|
170
|
+
def initialize(data)
|
171
|
+
@image = IS::ImagesServiceFactory.make_image(data.to_java_bytes)
|
172
|
+
end
|
173
|
+
|
174
|
+
def apply_transform(transform)
|
175
|
+
Image.new(data).deep_transform(transform)
|
176
|
+
end
|
177
|
+
|
178
|
+
def deep_transform(transform)
|
179
|
+
IS::Service.apply_transform(transform, @image)
|
180
|
+
self
|
181
|
+
end
|
182
|
+
|
183
|
+
def resize(width, height)
|
184
|
+
apply_transform IS::ImagesServiceFactory.make_resize(width, height)
|
185
|
+
end
|
186
|
+
|
187
|
+
def resize!(width, height)
|
188
|
+
@image = resize(width, height)
|
189
|
+
end
|
190
|
+
|
191
|
+
def rotate(degree)
|
192
|
+
apply_transform IS::ImagesServiceFactory.make_rotate(degree)
|
193
|
+
end
|
194
|
+
|
195
|
+
def rotate!(degree)
|
196
|
+
@image = rotate(degree)
|
197
|
+
end
|
198
|
+
|
199
|
+
def flip(direction = :horizontal)
|
200
|
+
if direction.to_sym == :horizontal
|
201
|
+
return apply_transform IS::ImagesServiceFactory.make_horizontal_flip
|
202
|
+
elsif direction.to_sym == :vertical
|
203
|
+
return apply_transform IS::ImagesServiceFactory.make_vertical_flip
|
204
|
+
else
|
205
|
+
raise ArgumentError, 'Direction must be :horizontal or :vertical'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def flip!(direction)
|
210
|
+
@image = flip(direction)
|
211
|
+
end
|
212
|
+
|
213
|
+
def crop(leftX, topY, rightX, bottomY)
|
214
|
+
apply_transform IS::ImagesServiceFactory.make_crop(leftX, topY, rightX, bottomY)
|
215
|
+
end
|
216
|
+
|
217
|
+
def crop!(leftX, topY, rightX, bottomY)
|
218
|
+
@image = crop(leftX, topY, rightX, bottomY)
|
219
|
+
end
|
220
|
+
|
221
|
+
def i_feel_lucky
|
222
|
+
apply_transform IS::ImagesServiceFactory.make_im_feeling_lucky
|
223
|
+
end
|
224
|
+
|
225
|
+
def i_feel_lucky!
|
226
|
+
@image = i_feel_lucky
|
227
|
+
end
|
228
|
+
|
229
|
+
def data
|
230
|
+
String.from_java_bytes @image.image_data
|
231
|
+
end
|
232
|
+
alias :to_s :data
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
data/lib/imagescience.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/ruby1.8 -w
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright 2009 Bas Wilbers
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'appengine-apis/images'
|
18
|
+
|
19
|
+
class ImageScience
|
20
|
+
Image = AppEngine::Images::Image
|
21
|
+
|
22
|
+
def self.with_image(path)
|
23
|
+
yield ImageScience.new(Image.open(path))
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.with_image_data(data)
|
27
|
+
yield ImageScience.new(Image.new(data))
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(image)
|
31
|
+
@image = image
|
32
|
+
end
|
33
|
+
|
34
|
+
def save(path)
|
35
|
+
File.open(path,"w") do |f|
|
36
|
+
f.write @image.to_s
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
@image.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def cropped_thumbnail(size) # :yields: image
|
45
|
+
width, height = self.width, self.height
|
46
|
+
left, top, right, bottom, half = 0, 0, width, half, (width - half).abs / 2
|
47
|
+
|
48
|
+
left, right = half, half + height if width > height
|
49
|
+
top, bottom = half, half + width if height > width
|
50
|
+
|
51
|
+
with_crop(left, top, right, bottom) do |img|
|
52
|
+
img.thumbnail(size) do |thumb|
|
53
|
+
yield thumb
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def resize(width, height)
|
59
|
+
yield @image.resize(width, height)
|
60
|
+
end
|
61
|
+
|
62
|
+
def thumbnail(size) # :yields: image
|
63
|
+
width, height = self.width, self.height
|
64
|
+
scale = size.to_f / (width > height ? width : height)
|
65
|
+
self.resize((width * scale).to_i, (height * scale).to_i) do |image|
|
66
|
+
yield image
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def with_crop(left, top, right, bottom)
|
71
|
+
cropped = @image.crop(left.to_f / width.to_f,
|
72
|
+
top.to_f / height.to_f ,
|
73
|
+
right.to_f / width.to_f,
|
74
|
+
bottom.to_f / height.to_f)
|
75
|
+
yield ImageScience.new(cropped)
|
76
|
+
end
|
77
|
+
|
78
|
+
def height
|
79
|
+
@image.height
|
80
|
+
end
|
81
|
+
|
82
|
+
def width
|
83
|
+
@image.width
|
84
|
+
end
|
85
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appengine-apis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Brown
|
@@ -9,106 +9,67 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-21 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
type: :
|
16
|
+
name: appengine-rack
|
17
|
+
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: "0"
|
24
24
|
version:
|
25
|
-
|
26
|
-
|
27
|
-
type: :development
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.11.0
|
34
|
-
version:
|
35
|
-
description: |-
|
36
|
-
APIs and utilities for using JRuby on Google App Engine.
|
37
|
-
|
38
|
-
To load the API stubs in IRB simply
|
39
|
-
require 'rubygems'
|
40
|
-
require 'appengine-apis/local_boot'
|
41
|
-
|
42
|
-
This will configure access to the same Datastore as running
|
43
|
-
|
44
|
-
$ dev_appserver.sh .
|
45
|
-
|
46
|
-
See these classes for an overview of each API:
|
47
|
-
- AppEngine::Logger
|
48
|
-
- AppEngine::Testing
|
49
|
-
- AppEngine::Users
|
50
|
-
- AppEngine::Mail
|
51
|
-
- AppEngine::Memcache
|
52
|
-
- AppEngine::URLFetch
|
53
|
-
- AppEngine::Datastore
|
54
|
-
- AppEngine::XMPP
|
55
|
-
- AppEngine::Labs::TaskQueue
|
56
|
-
|
57
|
-
Unless you're implementing your own ORM, you probably want to use the
|
58
|
-
DataMapper API instead of the lower level AppEngine::Datastore API.
|
59
|
-
email:
|
60
|
-
- ribrdb@gmail.com
|
25
|
+
description: Ruby API wrappers for App Engine
|
26
|
+
email: ribrdb@gmail.com
|
61
27
|
executables: []
|
62
28
|
|
63
29
|
extensions: []
|
64
30
|
|
65
31
|
extra_rdoc_files:
|
66
|
-
-
|
67
|
-
-
|
32
|
+
- README.rdoc
|
33
|
+
- COPYING
|
68
34
|
files:
|
69
|
-
-
|
70
|
-
- Manifest.txt
|
35
|
+
- COPYING
|
71
36
|
- README.rdoc
|
72
37
|
- Rakefile
|
73
38
|
- lib/appengine-apis.rb
|
74
|
-
- lib/
|
75
|
-
- lib/appengine-apis/datastore.rb
|
76
|
-
- lib/appengine-apis/datastore_types.rb
|
77
|
-
- lib/appengine-apis/labs/taskqueue.rb
|
39
|
+
- lib/imagescience.rb
|
78
40
|
- lib/appengine-apis/local_boot.rb
|
79
|
-
- lib/appengine-apis/
|
80
|
-
- lib/appengine-apis/mail.rb
|
41
|
+
- lib/appengine-apis/users.rb
|
81
42
|
- lib/appengine-apis/memcache.rb
|
82
|
-
- lib/appengine-apis/
|
43
|
+
- lib/appengine-apis/datastore_types.rb
|
83
44
|
- lib/appengine-apis/sdk.rb
|
84
45
|
- lib/appengine-apis/testing.rb
|
46
|
+
- lib/appengine-apis/labs/taskqueue.rb
|
47
|
+
- lib/appengine-apis/tempfile.rb
|
48
|
+
- lib/appengine-apis/images.rb
|
49
|
+
- lib/appengine-apis/logger.rb
|
85
50
|
- lib/appengine-apis/urlfetch.rb
|
86
|
-
- lib/appengine-apis/
|
51
|
+
- lib/appengine-apis/datastore.rb
|
52
|
+
- lib/appengine-apis/mail.rb
|
87
53
|
- lib/appengine-apis/xmpp.rb
|
88
|
-
- lib/appengine-apis/
|
89
|
-
-
|
90
|
-
- script/destroy
|
91
|
-
- script/generate
|
54
|
+
- lib/appengine-apis/merb-logger.rb
|
55
|
+
- lib/appengine-apis/apiproxy.rb
|
92
56
|
- spec/datastore_spec.rb
|
93
|
-
- spec/datastore_types_spec.rb
|
94
57
|
- spec/logger_spec.rb
|
95
|
-
- spec/mail_spec.rb
|
96
|
-
- spec/memcache_spec.rb
|
97
|
-
- spec/spec.opts
|
98
|
-
- spec/spec_helper.rb
|
99
58
|
- spec/taskqueue_spec.rb
|
100
59
|
- spec/urlfetch_spec.rb
|
101
|
-
- spec/
|
60
|
+
- spec/datastore_types_spec.rb
|
102
61
|
- spec/xmpp_spec.rb
|
103
|
-
-
|
62
|
+
- spec/memcache_spec.rb
|
63
|
+
- spec/mail_spec.rb
|
64
|
+
- spec/users_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
104
66
|
has_rdoc: true
|
105
67
|
homepage: http://code.google.com/p/appengine-jruby
|
106
68
|
licenses: []
|
107
69
|
|
108
70
|
post_install_message:
|
109
|
-
rdoc_options:
|
110
|
-
|
111
|
-
- README.rdoc
|
71
|
+
rdoc_options: []
|
72
|
+
|
112
73
|
require_paths:
|
113
74
|
- lib
|
114
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -125,10 +86,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
86
|
version:
|
126
87
|
requirements: []
|
127
88
|
|
128
|
-
rubyforge_project:
|
89
|
+
rubyforge_project:
|
129
90
|
rubygems_version: 1.3.5
|
130
91
|
signing_key:
|
131
92
|
specification_version: 3
|
132
|
-
summary:
|
93
|
+
summary: Ruby API wrappers for App Engine
|
133
94
|
test_files: []
|
134
95
|
|
data/History.txt
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
== 0.0.3 2009-04-25
|
2
|
-
|
3
|
-
* Added Memcache and Mail APIs
|
4
|
-
* Tries to automatically add SDK to your classpath if it's missing.
|
5
|
-
* Added AppEngine::Testing.boot to configure APIs for using in IRB.
|
6
|
-
|
7
|
-
== 0.0.2 2009-04-15
|
8
|
-
|
9
|
-
* Add URLFetch and Users APIs
|
10
|
-
|
11
|
-
== 0.0.1 2009-04-02
|
12
|
-
|
13
|
-
* Initial release
|
data/Manifest.txt
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
Manifest.txt
|
3
|
-
README.rdoc
|
4
|
-
Rakefile
|
5
|
-
lib/appengine-apis.rb
|
6
|
-
lib/appengine-apis/apiproxy.rb
|
7
|
-
lib/appengine-apis/datastore.rb
|
8
|
-
lib/appengine-apis/datastore_types.rb
|
9
|
-
lib/appengine-apis/labs/taskqueue.rb
|
10
|
-
lib/appengine-apis/local_boot.rb
|
11
|
-
lib/appengine-apis/logger.rb
|
12
|
-
lib/appengine-apis/mail.rb
|
13
|
-
lib/appengine-apis/memcache.rb
|
14
|
-
lib/appengine-apis/merb-logger.rb
|
15
|
-
lib/appengine-apis/sdk.rb
|
16
|
-
lib/appengine-apis/testing.rb
|
17
|
-
lib/appengine-apis/urlfetch.rb
|
18
|
-
lib/appengine-apis/users.rb
|
19
|
-
lib/appengine-apis/xmpp.rb
|
20
|
-
lib/appengine-apis/tempfile.rb
|
21
|
-
script/console
|
22
|
-
script/destroy
|
23
|
-
script/generate
|
24
|
-
spec/datastore_spec.rb
|
25
|
-
spec/datastore_types_spec.rb
|
26
|
-
spec/logger_spec.rb
|
27
|
-
spec/mail_spec.rb
|
28
|
-
spec/memcache_spec.rb
|
29
|
-
spec/spec.opts
|
30
|
-
spec/spec_helper.rb
|
31
|
-
spec/taskqueue_spec.rb
|
32
|
-
spec/urlfetch_spec.rb
|
33
|
-
spec/users_spec.rb
|
34
|
-
spec/xmpp_spec.rb
|
35
|
-
tasks/rspec.rake
|
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/appengine-apis.rb'}"
|
9
|
-
puts "Loading appengine-apis gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--colour
|
data/tasks/rspec.rake
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'spec'
|
3
|
-
rescue LoadError
|
4
|
-
require 'rubygems'
|
5
|
-
require 'spec'
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
require 'spec/rake/spectask'
|
9
|
-
rescue LoadError
|
10
|
-
puts <<-EOS
|
11
|
-
To use rspec for testing you must install rspec gem:
|
12
|
-
gem install rspec
|
13
|
-
EOS
|
14
|
-
exit(0)
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "Run the specs under spec/models"
|
18
|
-
Spec::Rake::SpecTask.new do |t|
|
19
|
-
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
-
end
|