Image dragcommand with dimensions


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/usr/bin/env ruby
  2.  
  3. if File.exists?(ENV['TM_BUNDLE_SUPPORT'] + "/bin/sips")
  4. SIPS = ENV['TM_BUNDLE_SUPPORT'] + "/bin/sips"
  5. else
  6. SIPS = "sips"
  7. end
  8.  
  9. imgsrc = `cygpath -m \"#{ENV['TM_DROPPED_FILEPATH']}\"`.chomp
  10. imgdims = `\'#{SIPS}\' -g pixelWidth -g pixelHeight \'#{imgsrc}\'`
  11. imgdims = imgdims.split("\n").collect { |dim| dim.gsub(/\D/,"") }
  12. alt = File.basename(imgsrc, ".*").gsub("\\","")
  13. print "<img src=\"#{ENV['TM_DROPPED_FILE']}\" width=\"#{imgdims[0]}\" height=\"#{imgdims[1]}\" alt=\"#{alt}\" title=\"#{alt}\"#{ENV['TM_XHTML']}>"

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.