Created
May 11, 2012 17:09
-
-
Save arieliten/2661063 to your computer and use it in GitHub Desktop.
Creating LTL labels
This file contains hidden or 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
s = Store.last | |
s_name = s.name.upcase | |
s_address = s.address.address_1 + s.address.address_2 | |
s_city = s.address.city | |
s_zip = 'Zip: ' + s.address.zipcode | |
label_path = Rails.root.join('public', 'images', 'ltl_label.png').to_s | |
barcode_file= "1318364275.png" ### <--- Aca ponete el string de un barcode que tengas en tu disco, en "public/images/barcodes/" | |
output_path = "#{Rails.root}/tmp/ltl_label_#{barcode_file}" | |
label = Magick::Image.read(label_path).first | |
barcode = Magick::Image.read("#{Rails.public_path}/images/barcodes/#{barcode_file}").first | |
barcode.resize!(140, 88) | |
#### Adding From | |
from = Magick::Image.new(150, 60) | |
gc = Magick::Draw.new | |
#gc.gravity = Magick::NorthGravity | |
#gc.font_family = "Helvetica" | |
#gc.stroke = 'none' | |
gc.pointsize = 12 | |
gc.annotate(from, 0, 0, 10, 13, "#{s_name}\n#{s_address}\n#{s_city}\n#{s_zip}") | |
result = label.composite!(barcode, Magick::SouthWestGravity, 13, 13, Magick::OverCompositeOp) | |
result = label.composite!(from, Magick::NorthWestGravity, 13, 33, Magick::OverCompositeOp) | |
result.write(output_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment