Skip to content

Instantly share code, notes, and snippets.

@ibizaman
Created June 7, 2016 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibizaman/a78aecdfd234e0bdf0a8b9b327fc8cf9 to your computer and use it in GitHub Desktop.
Save ibizaman/a78aecdfd234e0bdf0a8b9b327fc8cf9 to your computer and use it in GitHub Desktop.
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