We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

charlesroper on 03/19/07


Tagged

e-texteditor


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

gtcaz


Image dragcommand with dimensions


Published in: Ruby 


  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 

You need to login to post a comment.