mediaplug2-ruby 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/mediaplug/mediaplug_url.rb +127 -25
  2. metadata +2 -2
@@ -41,8 +41,8 @@ class MediaPlugURL
41
41
  argument = argument.split("x") if argument.is_a?(String)
42
42
  action << "width=#{argument[0]} height=#{argument[1]}"
43
43
  when Hash
44
- argument.keys.each{ |k| argument[k.to_s] = argument[k] }
45
- action << "#{"width=#{argument["width"]}" if argument["width"]}#{" height=#{argument["height"]}" if argument["height"]}"
44
+ argument.keys.each{ |k| argument[k.to_sym] = argument[k] }
45
+ action << "#{"width=#{argument[:width]}" if argument[:width]}#{" height=#{argument[:height]}" if argument[:height]}"
46
46
  end
47
47
 
48
48
  action << " format=#{@format}"
@@ -51,10 +51,10 @@ class MediaPlugURL
51
51
  self
52
52
  end
53
53
 
54
- # <b>Image Only:</b> Crop an image based on the input provided. Since
55
- # MediaPlug can crop according to gravity setting, default is center.
56
- # the arguments you
57
- # provide will determine which kind of cropping is employed.
54
+ # <b>Image Only:</b> Crop an image based on the input provided.
55
+ # Gravity setting applies to Image only, default is center.
56
+ # In Video Cropping, the cropping offset is default to [(original_width - crop_width)/2, (original_height - crop_height)/2] if no offset values are specified.
57
+ # the arguments you provide will determine which kind of cropping is employed.
58
58
  #
59
59
  # Cropping:
60
60
  #
@@ -65,33 +65,34 @@ class MediaPlugURL
65
65
 
66
66
  # Options:
67
67
  #
68
- # - <tt>:gravity</tt>: The position of crop. May be any of NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast. Default is center.
68
+ # - <tt>:gravity</tt>: *Image Only* The position of crop. May be any of NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast. Default is center.
69
69
  # - <tt>:x-offset</tt>: x coordinate offset of the top-left corner related to center position set by the gravity parameter.
70
70
  # - <tt>:y-offset</tt>: y coordinate offset of the top-left corner related to center position set by the gravity parameter.
71
71
  #
72
72
  #
73
73
  def crop(string_or_hash_or_array)
74
74
  argument = string_or_hash_or_array
75
- raise MediaPlug::InvalidAction, "Only images may be cropped." unless image?
76
- action = "crop "
75
+ raise MediaPlug::InvalidAction, "Only images or videos may be cropped." unless image? || video?
76
+ action = image? ? "crop " : "video_crop "
77
77
 
78
78
  case argument
79
79
  when String, Array
80
- argument = argument.split("x") if argument.is_a?(String)
81
- action << "gravity=center width=#{argument[0]} height=#{argument[1]}"
80
+ argument = argument.split("x") if argument.is_a?(String)
81
+ action << "gravity=center " if image?
82
+ action << "width=#{argument[0]} height=#{argument[1]} "
82
83
  when Hash
83
- argument.keys.each{|k| argument[k.to_s] = argument.delete(k)}
84
- action << "gravity=#{argument['gravity']} " if argument['gravity']
85
- action << "x-offset=#{argument['x-offset']} " if argument['x-offset']
86
- action << "y-offset=#{argument['y-offset']} " if argument['y-offset']
87
- if argument["width"] && argument["height"]
88
- action << " width=#{argument["width"]} height=#{argument["height"]}"
84
+ argument.keys.each{|k| argument[k.to_sym] = argument.delete(k)}
85
+ action << "gravity=#{argument[:gravity]} " if argument[:gravity] && image?
86
+ action << "x-offset=#{argument[:x_offset]} " if argument[:x_offset]
87
+ action << "y-offset=#{argument[:y_offset]} " if argument[:y_offset]
88
+ if argument[:width] && argument[:height]
89
+ action << "width=#{argument[:width]} height=#{argument[:height]} "
89
90
  else
90
91
  raise MediaPlug::InvalidAction, "Could not understand the options given to the crop command."
91
92
  end
92
93
  end
93
94
 
94
- action << " format=#{@format}"
95
+ action << "format=#{@format}"
95
96
  @actions << action
96
97
  self
97
98
  end
@@ -136,10 +137,15 @@ class MediaPlugURL
136
137
  # image = mp.image('http://some.url/')
137
138
  # image.flip(:both)
138
139
  def flip(direction)
139
- raise MediaPlug::InvalidAction, "Only images may be flipped." unless image?
140
+ raise MediaPlug::InvalidAction, "Only images or video may be flipped." unless image? || video?
140
141
  argument = direction
141
142
  argument = FLIP_MAP[argument.to_s] if FLIP_MAP.key?(argument.to_s)
143
+ if image?
142
144
  "flip #{argument} format=#{@format}"
145
+ else
146
+ "video_flip #{argument} format=#{@format}"
147
+ end
148
+ self
143
149
  end
144
150
  # <b>Image Only:</b> Create SWIRLING effect on the image by the given number of amplitude and wavelength.
145
151
  #
@@ -169,11 +175,12 @@ class MediaPlugURL
169
175
  def polaroid(options={})
170
176
  raise MediaPlug::InvalidAction, "Only images may be swirled." unless image?
171
177
  action = "polaroid "
178
+ options.keys.each{|k| options[k.to_sym] = options.delete(k)}
172
179
 
173
180
  action << "angle=#{options[:angle]} " if options[:angle]
174
181
  action << "caption=#{options[:caption]} " if options[:caption]
175
182
 
176
- action << " format=#{@format}"
183
+ action << "format=#{@format}"
177
184
  @actions << action
178
185
  self
179
186
  end
@@ -187,7 +194,7 @@ class MediaPlugURL
187
194
  raise MediaPlug::InvalidAction, "Only images may be swirled." unless image?
188
195
  action = "water_reflection "
189
196
 
190
- action << " format=#{@format}"
197
+ action << "format=#{@format}"
191
198
  @actions << action
192
199
  self
193
200
  end
@@ -204,9 +211,10 @@ class MediaPlugURL
204
211
  def filter(filter_type, options={})
205
212
  raise MediaPlug::InvalidAction, "Only images may be swirled." unless image?
206
213
  action = "filter "
207
- action << "filter_type=#{filter_type} "
214
+ action << "filter_type=#{filter_type} "
215
+ options.keys.each{|k| options[k.to_sym] = options.delete(k)}
208
216
  action << "level=#{options[:level]} " if options[:level]
209
- action << " format=#{@format}"
217
+ action << "format=#{@format}"
210
218
  @actions << action
211
219
  self
212
220
  end
@@ -242,22 +250,33 @@ class MediaPlugURL
242
250
  @actions << action
243
251
  self
244
252
  end
245
- # <b>Image Only:</b> Watermark an image with text or with another image.
253
+ # <b>Image Only:</b> Watermark an image with text or with another image
246
254
  # The +watermark_type+ may be +:image+ or +:text+.
247
255
  #
248
256
  # Options:
249
257
  #
250
258
  # - <tt>:gravity</tt>: The position of the watermark. May be any of NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast. Default is center.
251
259
  # - <tt>:alpha</tt>: value from 0.0 to 1.0 indicating the opacity of the watermark. Default is 0.6.
260
+ # - <tt>:x_offset</tt>: x coordinate offset of the top-left corner related to center position set by the gravity parameter.
261
+ # - <tt>:y_offset</tt>: y coordinate offset of the top-left corner related to center position set by the gravity parameter.
252
262
  #
253
263
  # Text-Only Options
254
264
  #
255
265
  # - <tt>:weight</tt>: the weight of the text font, maybe All,Bold,Bolder,Lighter,Normal. Default is Normal.
256
266
  # - <tt>:style</tt>: The style of the text font, maybe Any, Italic, Normal, Oblique
257
267
  # - <tt>:font_size</tt>: Integer, pixel size of the font to use on the watermark.
268
+ # - <tt>:font_type</tt>: Font type, possible values are:
269
+ # AvantGarde-Book, AvantGarde-BookOblique, AvantGarde-Demi, AvantGarde-DemiOblique, Bookman-Demi, Bookman-DemiItalic, Bookman-Light, Bookman-LightItalic
270
+ # Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique, Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Narrow, Helvetica-Narrow-Bold
271
+ # Helvetica-Narrow-BoldOblique, Helvetica-Narrow-Oblique, Helvetica-Oblique, Palatino-Bold, Palatino-BoldItalic, Palatino-Italic, Palatino-Roman
272
+ # Symbol, Times-Bold, Times-BoldItalic, Times-Italic, Times-Roman, Century-Schoolbook-Bold, Century-Schoolbook-Bold-Italic, Century-Schoolbook-Italic
273
+ # Century-Schoolbook-Roman, DejaVu-Sans-Bold, DejaVu-Sans-Book, DejaVu-Sans-Mono-Bold, DejaVu-Sans-Mono-Book, DejaVu-Serif-Bold, DejaVu-Serif-Book
274
+ # Dingbats-Regular, URW-Chancery-Medium-Italic
275
+
258
276
  def watermark(watermark_type, text_or_url, options = {})
259
277
  raise MediaPlug::InvalidAction, "Only images may be watermarked." unless image?
260
278
  action = "watermark "
279
+ options.keys.each{|k| options[k.to_sym] = options.delete(k)}
261
280
 
262
281
  case watermark_type
263
282
  when :image
@@ -267,24 +286,49 @@ class MediaPlugURL
267
286
  action << "style=#{options[:style]} " if options[:style]
268
287
  action << "weight=#{options[:weight]} " if options[:weight]
269
288
  action << "text-font-size=#{options[:font_size]} " if options[:font_size]
289
+ action << "font-type=#{options[:font_type]} " if options[:font_type]
270
290
  else
271
291
  raise MediaPlug::InvalidAction, "The watermark_type must be :image or :text"
272
292
  end
273
293
 
274
294
  action << "gravity=#{options[:gravity]} " if options[:gravity]
275
295
  action << "alpha=#{options[:alpha]} " if options[:alpha]
296
+ action << "x-offset=#{argument[:x_offset]} " if argument[:x_offset]
297
+ action << "y-offset=#{argument[:y_offset]} " if argument[:y_offset]
298
+
276
299
  action << "format=#{@format}"
277
300
 
278
301
  @actions << action
279
302
  self
280
303
  end
304
+ # <b>Image Only:</b> Apply detection filters to the Image.
305
+ # - <tt>:detection_type</tt>: can be Face, Background, or Edge.
306
+ # Face detection automatically detect faces in the image using Computer Vision Algorithm,
307
+ # and draws retangular around the detected area.
308
+ # Edge detection detects edges in the image.
309
+ # background removal automatically create transparent background using AI algorithm.
310
+
311
+ # Example:
312
+ #
313
+ # image = mp.image('http://some.url/')
314
+ # image.detection('Face') #apply face detection on the Image
281
315
 
316
+ def detection(detection_type, options = {})
317
+ raise MediaPlug::InvalidAction, "Only images may be detected." unless image?
318
+ action = "detection "
319
+
320
+ action << "type=#{detection_type} "
321
+ action << "format=#{@format}"
322
+
323
+ @actions << action
324
+ self
325
+ end
282
326
  # Converts the source into the specified format, with the options provided
283
327
  # (options vary based on media type).
284
328
  #
285
329
  # Allowable Formats:
286
330
  #
287
- # - <b>Video:</b> flv, ipod, psp, 3gpp
331
+ # - <b>Video:</b> flv, mp4, mov, ipod, psp, 3gpp
288
332
  # - <b>Audio:</b> mp3
289
333
  # - <b>Image:</b> jpg, png, gif
290
334
  #
@@ -299,6 +343,8 @@ class MediaPlugURL
299
343
  # - <tt>:bitrate</tt>: The bitrate in which to encode (e.g. "64k")
300
344
  # - <tt>:samplerate</tt>: The sample rate with which to encode (e.g. 128)
301
345
  def convert(new_format, options = {})
346
+ options.keys.each{|k| options[k.to_sym] = options.delete(k)}
347
+
302
348
  if image?
303
349
  action = "rotate 0 format=#{new_format}"
304
350
  elsif audio?
@@ -322,6 +368,8 @@ class MediaPlugURL
322
368
  # - <tt>:height</tt>: The height of thumbnail image
323
369
  def thumbnail(seek, options={})
324
370
  raise MediaPlug::InvalidAction, "Only videos may be thumbnailed." unless video?
371
+ options.keys.each{|k| options[k.to_sym] = options.delete(k)}
372
+
325
373
  action = "thumbnail seek=#{seek}"
326
374
  action << " width=#{options[:width]}" if options[:width]
327
375
  action << " height=#{options[:height]}" if options[:height]
@@ -338,6 +386,8 @@ class MediaPlugURL
338
386
  # - <tt>:height</tt>: The height of thumbnail image
339
387
  def preview(framestep, options={})
340
388
  raise MediaPlug::InvalidAction, "Only videos may be previewed." unless video?
389
+ options.keys.each{|k| options[k.to_sym] = options.delete(k)}
390
+
341
391
  action = "preview framestep=#{framestep}"
342
392
  action << " width=#{options[:width]}" if options[:width]
343
393
  action << " height=#{options[:height]}" if options[:height]
@@ -345,6 +395,58 @@ class MediaPlugURL
345
395
  @actions << action
346
396
  self
347
397
  end
398
+ # <b>Video Only:</b> Add text water mark to a video
399
+ # Video Watermark Options:
400
+ #
401
+ # - <tt>:font_size</tt>: Integer, pixel size of the font to use on the watermark.
402
+ # - <tt>:font_type</tt>: Font type, possible values are:
403
+ # AvantGarde-Book, AvantGarde-BookOblique, AvantGarde-Demi, AvantGarde-DemiOblique, Bookman-Demi, Bookman-DemiItalic, Bookman-Light, Bookman-LightItalic
404
+ # Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique, Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Narrow, Helvetica-Narrow-Bold
405
+ # Helvetica-Narrow-BoldOblique, Helvetica-Narrow-Oblique, Helvetica-Oblique, Palatino-Bold, Palatino-BoldItalic, Palatino-Italic, Palatino-Roman
406
+ # Symbol, Times-Bold, Times-BoldItalic, Times-Italic, Times-Roman, Century-Schoolbook-Bold, Century-Schoolbook-Bold-Italic, Century-Schoolbook-Italic
407
+ # Century-Schoolbook-Roman, DejaVu-Sans-Bold, DejaVu-Sans-Book, DejaVu-Sans-Mono-Bold, DejaVu-Sans-Mono-Book, DejaVu-Serif-Bold, DejaVu-Serif-Book
408
+ # Dingbats-Regular, URW-Chancery-Medium-Italic
409
+ # - <tt>:x_offset</tt>: integer, x-offset, x coordiante for the location of the top left corner of text watermark
410
+ # - <tt>:y_offset</tt>: integer, y-offset, y coordiante for the location of the top left corner of text watermark
411
+ # - <tt>:font_color</tt>: The color to be used for drawing fonts. Either a string (e.g. "red") or in 0xRRGGBB[AA] format (e.g. "0xff000033"), possibly followed by an alpha specifier (red@0.2 red withe alpah = 0.2).
412
+ # The default value of fontcolor is "0x80acbc44".
413
+ # - <tt>:bg_color</tt>: The color to be used for drawing box around text. Either a string (e.g. "yellow") or in 0xRRGGBB[AA] format (e.g. "0xff00ff"), possibly followed by an alpha specifier (red@0.2 red withe alpah = 0.2).
414
+ # If no value is specified, no box will be drawn around the text.
415
+
416
+ def video_watermark(text, options={})
417
+ raise MediaPlug::InvalidAction, "Only videos may be video watermarked." unless video?
418
+ options.keys.each{|k| options[k.to_sym] = options.delete(k)}
419
+
420
+ action = "video_watermark text=#{text}"
421
+ action << " text-font-size=#{options[:font_size]}" if options[:font_size]
422
+ action << " x-offset=#{argument[:x_offset]} " if argument[:x_offset]
423
+ action << " y-offset=#{argument[:y_offset]} " if argument[:y_offset]
424
+ action << " font-color=#{options[:font_color]}" if options[:font_color]
425
+ action << " bg-color=#{options[:bg_color]}" if options[:bg_color]
426
+ action << " format=#{@format}"
427
+
428
+ @actions << action
429
+ self
430
+ end
431
+
432
+ # <b>Video and Audio Only:</b> Clip the video or audio to any duration and starts at the specified time.
433
+ # Video Preview Options:
434
+ #
435
+ # Framestep is duration in seconds of per frame capture
436
+ # - <tt>:width</tt>: The width of thumbnail image
437
+ # - <tt>:height</tt>: The height of thumbnail image
438
+ def clipping(start_at, duration, options={})
439
+ raise MediaPlug::InvalidAction, "Only audio or video may be clipped." unless video? or audio?
440
+
441
+ action = video? ? "video_clipping " : "audio_clipping "
442
+
443
+ action << " start=#{start_at}" if start_at
444
+ action << " duration=#{duration}" if duration
445
+ action << " format=#{@format}"
446
+
447
+ @actions << action
448
+ self
449
+ end
348
450
  # Causes the resultant URL to be recached. Should not be called
349
451
  # each time.
350
452
  def recache!
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mediaplug2-ruby
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Bleigh
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-07-18 00:00:00 -05:00
14
+ date: 2011-08-16 00:00:00 -05:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency