Created
June 7, 2016 00:04
-
-
Save ibizaman/a78aecdfd234e0bdf0a8b9b327fc8cf9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def jpeg_size(path) do | |
bin = File.read!(WPI.Database.Media.complete_path(path)) | |
case jpeg_size(path, bin, {}) do | |
{} -> nil | |
size -> size | |
end | |
end | |
def jpeg_size(path, << 255, 192, 0, 17, 8, height::size(16), width::size(16), rest::binary >>, size) do | |
if {width, height} > size do | |
jpeg_size(path, rest, {width, height}) | |
else | |
jpeg_size(path, rest, size) | |
end | |
end | |
def jpeg_size(path, << _, bin::binary >>, size) do | |
jpeg_size(path, bin, size) | |
end | |
def jpeg_size(path, << >>, size) do | |
size | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment