added Qiniu::RS::Image.exif()

This commit is contained in:
404
2012-07-28 19:06:35 +08:00
parent e5c57d4d72
commit b2b5b8b92d
8 changed files with 56 additions and 10 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
qiniu-rs (2.3.2)
qiniu-rs (2.3.3)
json (~> 1.7.3)
mime-types (~> 1.19)
rest-client (~> 1.6.7)
+22 -2
View File
@@ -31,6 +31,7 @@ title: Ruby SDK 使用指南 | 七牛云存储
- [取消公开外链](#unpublish)
- [图像处理](#op-image)
- [查看图片属性信息](#image_info)
- [查看图片EXIF信息](#image_exif)
- [获取指定规格的缩略图预览地址](#image_preview_url)
- [高级图像处理(缩略、裁剪、旋转、转化)](#image_mogrify_preview_url)
- [高级图像处理(缩略、裁剪、旋转、转化)并持久化](#image_mogrify_save_as)
@@ -484,6 +485,24 @@ height
colorModel
: 原始图片着色模式
<a name="image_exif"></a>
#### 查看图片EXIF信息
Qiniu::RS.image_exif(url)
使用 SDK 提供的 `Qiniu::RS.image_exif` 方法,可以基于一张存储于七牛云存储服务器上的原始图片图片,取到该图片的 EXIF 信息。
**参数**
url
: 必须,字符串类型(String),原图的下载链接,需是 `Qiniu::RS.get`(或`Qiniu::RS.batch_get`)函数返回值中 `url` 字段的值,或者是 `Qiniu::RS.download`(或`Qiniu::RS.batch_download`)函数返回的下载链接。且文件本身必须是图片。
**返回值**
如果参数 `url` 所代表的图片没有 EXIF 信息,返回 `false`。否则,返回一个包含 EXIF 信息的 Hash 结构。
<a name="image_preview_url"></a>
#### 获取指定规格的缩略图预览地址
@@ -505,6 +524,7 @@ spec
返回一个字符串类型的缩略图 URL
<a name="image_mogrify_preview_url"></a>
#### 高级图像处理(缩略、裁剪、旋转、转化)
@@ -533,7 +553,7 @@ mogrify_options
:auto_orient => <TrueOrFalse>
}
`Qiniu::RS.image_mogrify_preview_url()` 方法是对七牛云存储图像处理高级接口的完整包装,关于 `mogrify_options` 参数里边的具体含义和使用方式,可以参考文档:[图像处理高级接口](#/v2/api/foimg/#fo-imageMogr)。
`Qiniu::RS.image_mogrify_preview_url()` 方法是对七牛云存储图像处理高级接口的完整包装,关于 `mogrify_options` 参数里边的具体含义和使用方式,可以参考文档:[图像处理高级接口](/v2/api/foimg/#fo-imageMogr)。
**返回值**
@@ -574,7 +594,7 @@ mogrify_options
:auto_orient => <TrueOrFalse>
}
`Qiniu::RS::Image.mogrify_preview_url()` 方法是对七牛云存储图像处理高级接口的完整包装,关于 `mogrify_options` 参数里边的具体含义和使用方式,可以参考文档:[图像处理高级接口](#/v2/api/foimg/#fo-imageMogr)。
`Qiniu::RS::Image.mogrify_preview_url()` 方法是对七牛云存储图像处理高级接口的完整包装,关于 `mogrify_options` 参数里边的具体含义和使用方式,可以参考文档:[图像处理高级接口](/v2/api/foimg/#fo-imageMogr)。
**返回值**
+5
View File
@@ -124,6 +124,11 @@ module Qiniu
code == StatusOK ? data : false
end
def image_exif(url)
code, data = Image.exif(url)
code == StatusOK ? data : false
end
def image_preview_url(url, spec)
Image.preivew_url(url, spec)
end
+5 -1
View File
@@ -10,6 +10,10 @@ module Qiniu
Utils.http_request url + '/imageInfo', nil, {:method => :get}
end
def exif(url)
Utils.http_request url + '?exif', nil, {:method => :get}
end
def preivew_url(url, spec)
url + '/imagePreview/' + spec.to_s
end
@@ -29,7 +33,7 @@ module Qiniu
params_string += %Q(/#{key}/#{opts[key]}) unless opts[key].nil?
end
params_string += '/auto-orient' unless opts["auto_orient"].nil?
'imageMogr' + params_string
'imageMogr' + URI.escape(params_string)
end
end
+2 -2
View File
@@ -49,10 +49,10 @@ module Qiniu
header_options.merge!('Authorization' => auth_token) unless auth_token.nil?
case options[:method]
when :get
response = RestClient.get url, header_options
response = RestClient.get(url, header_options)
when :post
header_options.merge!(:content_type => options[:content_type])
response = RestClient.post url, data, header_options
response = RestClient.post(url, data, header_options)
end
code = response.respond_to?(:code) ? response.code.to_i : 0
if code != 200
+1 -1
View File
@@ -2,6 +2,6 @@
module Qiniu
module RS
VERSION = "2.3.2"
VERSION = "2.3.3"
end
end
+8 -2
View File
@@ -36,7 +36,6 @@ module Qiniu
:file => local_file,
:bucket => @bucket,
:key => @key,
:mime_type => "image/png",
:enable_crc32_check => true
result.should be_true
@@ -47,7 +46,7 @@ module Qiniu
@source_image_url = result["url"]
@mogrify_options = {
:thumbnail => "!120x120r",
:thumbnail => "!120x120>",
:gravity => "center",
:crop => "!120x120a0a0",
:quality => 85,
@@ -65,6 +64,13 @@ module Qiniu
end
end
context ".exif" do
it "should works" do
code, data = Qiniu::RS::Image.exif(@source_image_url)
puts data.inspect
end
end
context ".mogrify_preview_url" do
it "should works" do
mogrify_preview_url = Qiniu::RS::Image.mogrify_preview_url(@source_image_url, @mogrify_options)
+12 -1
View File
@@ -164,6 +164,17 @@ module Qiniu
end
end
context ".image_exif" do
it "should works" do
data = Qiniu::RS.get(@test_image_bucket, @test_image_key)
data.should_not be_false
data.should_not be_empty
puts data.inspect
result = Qiniu::RS.image_exif(data["url"])
puts result.inspect
end
end
context ".image_mogrify_save_as" do
it "should works" do
data = Qiniu::RS.get(@test_image_bucket, @test_image_key)
@@ -175,7 +186,7 @@ module Qiniu
dest_key = "cropped-" + @test_image_key
src_img_url = data["url"]
mogrify_options = {
:thumbnail => "!120x120r",
:thumbnail => "!120x120>",
:gravity => "center",
:crop => "!120x120a0a0",
:quality => 85,