Skip to Main Content
Ruby. Receptury
book

Ruby. Receptury

by Lucas Carlson, Leonard Richardson
November 2012
Intermediate to advanced content levelIntermediate to advanced
888 pages
54h 46m
Polish
Helion
Content preview from Ruby. Receptury

12.2. Dodawanie tekstu do grafiki

Podziękowania dla: Antonio Cangiano

Problem

Chcemy wprowadzić tekst do grafiki — na przykład podpis lub notkę o prawach autorskich.

Rozwiązanie

Należy utworzyć obiekt Draw dostępny w module RMagick i wywołać jego metodę annotate z argumentami w postaci nazwy pliku graficznego i tekstu, który należy w nim umieścić.

Poniższy kod dodaje notkę o prawach autorskich '© NPS' w prawym dolnym rogu grafiki zapisanej w pliku canyon.png. W kodzie ustawiono również czcionkę, kolor, rozmiar i inne właściwości tekstu:

require 'rubygems' require 'RMagick' img = Magick::Image.read('canyon.png').first my_text = "\251 NPS" copyright = Magick::Draw.new copyright.annotate(img, 0, 0, 3, 18, my_text) do self.font = ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ReasonML Quick Start Guide

ReasonML Quick Start Guide

Raphael Rafatpanah, Bruno Joseph D'mello
Microsoft Excel: Formeln & Funktionen - Das Maxibuch, 3., aktualisierte und erweiterte Auflage

Microsoft Excel: Formeln & Funktionen - Das Maxibuch, 3., aktualisierte und erweiterte Auflage

Egbert Jeschke, Eckehard Pfeifer, Helmut Reinke, Sara Unverhau, Bodo Fienitz
Mastering Ruby Closures

Mastering Ruby Closures

Benjamin Tan Wei Hao

Publisher Resources

ISBN: 9781457177453Errata Page