8000 'Type' method for image types by tayler1 · Pull Request #10 · sstephenson/dimensions · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 10, 2018. It is now read-only.

'Type' method for image types #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ Dimensions.width("upload_bird.jpg") # => 300
Dimensions.height("upload_bird.jpg") # => 225
```

Use the `type` method to get image type:

```ruby
Dimensions.type("upload_bird.jpg") # => :jpeg
Dimensions.type("wrong_ext.txt") # => :png
```

Many cameras and smartphones set the EXIF orientation attribute for
photos taken in portrait or landscape mode. The Dimensions library
reads this attribute and swaps the `width` and `height` values
Expand Down
5 changes: 5 additions & 0 deletions lib/dimensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def height(path)
io_for(path).height
end

# Returns the type of the image at the given path.
def type(path)
io_for(path).type
end

# Returns the rotation angle of the JPEG image at the given
# path. If the JPEG is rotated 90 or 270 degrees (as is often the
# case with photos from smartphones, for example) its width and
Expand Down
5 changes: 5 additions & 0 deletions lib/dimensions/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def angle
@reader.angle
end

def type
peek
@reader.type
end

private
def peek
unless no_peeking?
Expand Down
0