Perl Graphics Programming

Total Page:16

File Type:pdf, Size:1020Kb

Perl Graphics Programming Perl Graphics Programming Shawn Wallace O'REILLY8 Beijing • Cambridge • Farnham • Koln • Paris • Sebastopol • Taipei • Tokyo Table of Contents Preface ix Part I. Raster Images and Web Graphics 1. Creating Graphics with Perl 3 Introduction tq File Formats 3 Color 5 Raster File Formats 10 Vector Graphic File Formats 17 Document File Formats 21 References 24 2. On-the-Fly Graphics with GD 25 GD Basics 26 Sample GD Applications 27 Reading and Writing Methods 35 Getting and Setting General Information 40 Color Table Manipulation Methods 41 Brushes, Styles, and Tiles 44 Copying and Transforming Images 48 Image Drawing and Manipulation Methods 50 Strings and Fonts 53 Polygon Methods 55 3. Graphics Scripting with lmage::Magick 62 What Is ImageMagick? 62 Using Image ::Magick 65 Sample Image: :Magick Applications 70 Reading and Writing Images 79 Retrieving and Setting File Information 82 Sizing and Transforming Images 86 Copying and Composing Tfriages 91 Color and Transparency 95 Annotation and Drawing 100 Filters and Effects 106 4. ChartsandGraphswithGD::Graph 117 Let's Make Some Graphs! 117 A Sample GD::Graph Application 125 GD::Graph Methods 130 Attributes of GD::Graph Objects 134 Colors and Fonts in GD::Graph 142 5. Scripting the Gimp with Perl 145 Getting and Installing the Gimp 145 Writing Gimp Plug-ins in Perl 148 Your First Gimp Script 150 Object-Oriented Versus Procedural Scripting 155 Adding New Features to the Gimp 158 Standalone Scripts 171 Part II. Vector Images and Animations 6. SVG: The Scalable Vector Graphics Format 175 SVG Document Structure 176 The Basic SVG Tags 180 7. Creating SVG with Perl 195 A Slide-Show Presentation 195 SVG Animation 201 Creating a Bouncing Ball 202 SVG Scripting with JavaScript 204 Using Unicode Text in SVG Images 208 Transformation with XSLT and Perl 210 Table of Contents 8. SWF: The Flash File Format 215 The History of Flash and SWF 215 The Format and Function of SWF Files 216 Anatomy of'a Tag 223 Parsing an SWF File with Perl 233 9. Using Ming 238 Installation 238 Overview of the Perl Interface 239 The Astral Trespassers Game 240 The SWF Module 246 The SWF::Movie Module 247 The SWF::Sprite (or SWF::MovieClip) Module 249 The SWF::DisplayItem Module 250 The SWF::Shape Module 254 The SWF: :Button Module 259 The SWF: :Bitmap Module 262 The SWF: :Text Module 263 The SWF::TextField Module 265 The SWF .-.Font Module 267 The SWF::Fill Module 268 The SWF::Gradient Module 269 The SWF::Morph Module 269 The SWF: :Sound Module 272 The SWF::Action Module 272 SWF Recipes 273 Part III. Documents and Printing 10. Printing with Postscript and PDF 291 PostScript in a Nutshell 291 Portable Document Format (PDF) 299 References 314 11. Using the PostScript Modules 315 Creating PostScript from a Web Interface 316 The PostScript: :TextBlock Module 320 The PostScript::Document Module 326 Table of Contents I vii The PostScript::Elements Module 328 Other PostScript Modules 332 12. Creating PDF Documents with Perl 333 Introduction to PDF::API2 333 Creating Address Labels 336 Adding to Existing PDF Files 341 PDF::API2 Reference 343 PDF::API2::Page 347 PDF::API2::Content 349 PDF::API2::Gfx 353 PDF::API2::Text 355 PDF::API2::Outline 357 References 360 Part IV. Appendixes A. Serving Graphics on the Web 363 B. Gimp Reference 385 C. lmage::Magick File Formats 413 D. ActionScript Reference 418 Index 437 viii I Table of Contents.
Recommended publications
  • XMP SPECIFICATION PART 3 STORAGE in FILES Copyright © 2016 Adobe Systems Incorporated
    XMP SPECIFICATION PART 3 STORAGE IN FILES Copyright © 2016 Adobe Systems Incorporated. All rights reserved. Adobe XMP Specification Part 3: Storage in Files NOTICE: All information contained herein is the property of Adobe Systems Incorporated. No part of this publication (whether in hardcopy or electronic form) may be reproduced or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written consent of Adobe Systems Incorporated. Adobe, the Adobe logo, Acrobat, Acrobat Distiller, Flash, FrameMaker, InDesign, Illustrator, Photoshop, PostScript, and the XMP logo are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. MS-DOS, Windows, and Windows NT are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Apple, Macintosh, Mac OS and QuickTime are trademarks of Apple Computer, Inc., registered in the United States and other countries. UNIX is a trademark in the United States and other countries, licensed exclusively through X/Open Company, Ltd. All other trademarks are the property of their respective owners. This publication and the information herein is furnished AS IS, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies, makes no warranty of any kind (express, implied, or statutory) with respect to this publication, and expressly disclaims any and all warranties of merchantability, fitness for particular purposes, and noninfringement of third party rights. Contents 1 Embedding XMP metadata in application files .
    [Show full text]
  • Encapsulated Postscript File Format Specification
    ® Encapsulated PostScript File Format Specification ®® Adobe Developer Support Version 3.0 1 May 1992 Adobe Systems Incorporated Adobe Developer Technologies 345 Park Avenue San Jose, CA 95110 http://partners.adobe.com/ PN LPS5002 Copyright 1985–1988, 1990, 1992 by Adobe Systems Incorporated. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written consent of the publisher. Any software referred to herein is furnished under license and may only be used or copied in accordance with the terms of such license. PostScript is a registered trademark of Adobe Systems Incorporated. All instances of the name PostScript in the text are references to the PostScript language as defined by Adobe Systems Incorpo- rated unless otherwise stated. The name PostScript also is used as a product trademark for Adobe Sys- tems’ implementation of the PostScript language interpreter. Any references to a “PostScript printer,” a “PostScript file,” or a “PostScript driver” refer to printers, files, and driver programs (respectively) which are written in or support the PostScript language. The sentences in this book that use “PostScript language” as an adjective phrase are so constructed to rein- force that the name refers to the standard language definition as set forth by Adobe Systems Incorpo- rated. PostScript, the PostScript logo, Display PostScript, Adobe, the Adobe logo, Adobe Illustrator, Tran- Script, Carta, and Sonata are trademarks of Adobe Systems Incorporated registered in the U.S.A. and other countries. Adobe Garamond and Lithos are trademarks of Adobe Systems Incorporated.
    [Show full text]
  • Microsoft Powerpoint
    Development of Multimedia WebApp on Tizen Platform 1. HTML Multimedia 2. Multimedia Playing with HTML5 Tags (1) HTML5 Video (2) HTML5 Audio (3) HTML Pulg-ins (4) HTML YouTube (5) Accessing Media Streams and Playing (6) Multimedia Contents Mgmt (7) Capturing Images 3. Multimedia Processing Web Device API Multimedia WepApp on Tizen - 1 - 1. HTML Multimedia • What is Multimedia ? − Multimedia comes in many different formats. It can be almost anything you can hear or see. − Examples : Pictures, music, sound, videos, records, films, animations, and more. − Web pages often contain multimedia elements of different types and formats. • Multimedia Formats − Multimedia elements (like sounds or videos) are stored in media files. − The most common way to discover the type of a file, is to look at the file extension. ⇔ When a browser sees the file extension .htm or .html, it will treat the file as an HTML file. ⇔ The .xml extension indicates an XML file, and the .css extension indicates a style sheet file. ⇔ Pictures are recognized by extensions like .gif, .png and .jpg. − Multimedia files also have their own formats and different extensions like: .swf, .wav, .mp3, .mp4, .mpg, .wmv, and .avi. Multimedia WepApp on Tizen - 2 - 2. Multimedia Playing with HTML5 Tags (1) HTML5 Video • Some of the popular video container formats include the following: Audio Video Interleave (.avi) Flash Video (.flv) MPEG 4 (.mp4) Matroska (.mkv) Ogg (.ogv) • Browser Support Multimedia WepApp on Tizen - 3 - • Common Video Format Format File Description .mpg MPEG. Developed by the Moving Pictures Expert Group. The first popular video format on the MPEG .mpeg web.
    [Show full text]
  • Web Compatible SAS/GRAPH Output the Easy
    Web Compatible SAS/GRAPH® Output the Easy Way Ahsan Ullah, Pinkerton Computer Consultants, Inc., Alexandria, VA ABSTRACT • Proper use of colors is a must to make the image attractive. • (TM) This paper describes some concepts and analyses required If there is an option to print the image, a PostScript to create SAS/GRAPH images for use in WEB pages. It file needs to be tagged along with the image which will deals with an automated SAS/AF® Frame system designed to keep the usual form of the printed output create and print a number of graphs and produce suitable • In order to print a hard copy of the graph from the graph image files for inclusion on WEB pages. Topics internet, a PostScript color or black and white with discussed include drill-down design, programming minimum of 0.5 X 0.5 inch margin should be selected. (TM) techniques for creating GIF files, and the creation of custom Most Hewlett Packard printers satisfy the SAS Device Drivers. requirements. INTRODUCTION A user-friendly SAS/AF Frame system needs to be created to perform the following functions: • Interactive or batch process to create images. SAS software is a major leader in information and • Support the selection of device drivers to print or management systems. It has powerful features that support transport postscript or GIF file. the creation of customized hard copy output that includes • both data and graphic output. Until now, SAS custom graphs Automatically add HTML code to create Web-ready could not take their place in the Web world because of: graph images • Sophistication of SAS custom graphs • True portability across platforms Device Drivers • Interactive way to create and process graphs A GIF device driver is needed for SAS software to create a GIF Image file of the graph.
    [Show full text]
  • There Are 2 Types of Files in the Graphics World Bit Mapped (RASTER)
    There are 2 Types of Files in the Graphics World Bit Mapped (RASTER) • There are two kinds of computer graphics: Bit Mapped (RASTER) and Object Oriented (VECTOR). Bit mapped graphics are graphics that are stored in the form of a bitmap. They are a sequence of bits that get drawn onto the screen. You create bit mapped graphics using a painting program. • When you enlarge a bit mapped image, you will get a pixelated look. If you are planning to print out an image that was originally 3 inches on 3 inches as 6 inches by 6 inches, you will get a very pixelated look. • Bit mapped graphics tend to create larger files than object oriented graphics. • As you can see from these two pictures, when a bitmapped image gets scaled up, the detail is lost, as opposed to an object oriented drawing where no pixelation occurs. Key Points of Raster Images pixels in a grid resolution dependent resizing reduces quality easily converted restricted to rectangle minimal support for transparency Object Oriented (VECTOR) Definition: Vector graphics are made up of many individual objects. Each of these objects can be defined by mathematical statements and has individual properties assigned to it such as color, fill, and outline. Vector graphics are resolution independent because they can be output to the highest quality at any scale. Software used to create vector graphics is sometimes referred to as object-based editing software. Common vector formats include AI (Adobe Illustrator), CDR (CorelDRAW), CGM (Computer Graphics Metafile), SWF (Shockwave Flash), and DXF (AutoCAD and other CAD software).
    [Show full text]
  • 5Lesson 5: Multimedia on the Web
    5Lesson 5: Multimedia on the Web Objectives By the end of this lesson, you will be able to: 1.5.7: Download and store files using a Web browser. 1.5.10: Install and upgrade common plug-ins, add-ons and viewers (e.g., Adobe Reader, Adobe Flash Player, Microsoft Silverlight, Windows Media Player, Apple QuickTime) and identify their common file name extensions. 1.5.11: Use document and multimedia file formats, including PDF, PNG, RTF, PostScript (PS), AVI, MPEG, MP3, MP4, Ogg. Convert between file formats when appropriate. 5-2 Internet Business Associate Pre-Assessment Questions 1. Briefly describe C++. 2. Which statement about vector graphics is true? a. Vector graphics are saved as sequences of vector statements. b. Vector graphics have much larger file sizes than raster graphics. c. Vector graphics are pixel-based. d. GIFs and JPGs are vector graphics. 3. Name at least two examples of browser plug-ins. © 2014 Certification Partners, LLC. — All Rights Reserved. Version 2.1 Lesson 5: Multimedia on the Web 5-3 Introduction to Multimedia on the Web NOTE: Multimedia on the Web has expanded rapidly as broadband connections have allowed Multimedia use on users to connect at faster speeds. Almost all Web sites, including corporate sites, feature the Web has been hindered by multimedia content and interactive objects. For instance, employee orientation sessions, bandwidth audio and video memos, and training materials are often placed on the Internet or limitations. Until all Internet users have corporate intranets. high-speed connections Nearly all network-connected devices, such as PCs, tablets, smartphones and smart TVs, (broadband or can view online interactive multimedia.
    [Show full text]
  • Webp/ Content Type Avg # of Requests Avg Size HTML 6 39 Kb Images 39 490 Kb 69% Javascript 10 142 Kb CSS 3 27 Kb
    WebRTC enabling faster, smaller and more beautiful web Stephen Konig [email protected] Ilya Grigorik [email protected] https://developers.google.com/speed/webp/ Content Type Avg # of Requests Avg size HTML 6 39 kB Images 39 490 kB 69% Javascript 10 142 kB CSS 3 27 kB HTTP Archive - Mobile Trends (Feb, 2013) @igrigorik It's a HiDPI world... Tablet dimension device-width px/inch Nexus 7 3.75 603 ~ 160 Kindle Fire 3.5 600 ~ 170 iPad Mini 4.75 768 ~ 160 PlayBook 3.54 600 ~ 170 Galaxy 7'' (2nd gen) 3.31 600 ~ 180 Macbook + Retina 15.4 2880 ~ 220 Chromebook Pixel 12.85 2560 ~ 239 HiDPI screens require 4x pixels! Without careful optimization, this would increase the size of our pages by a huge margin - from 500KB to ~2000 KB! Which image format should I use? Wrong question! Instead, what if we had one format with all the benefits and features? ● Lossy and lossless compression ● Transparency (alpha channel) ● Great compression for photos ● Animation support ● Metadata ● Color profiles ● .... That's WebP! Brief history of WebP... ● WebM video format uses VP8 video codec ● WebP is derived from VP8, essentially a key frame... ● Web{P,M} are open-source, royalty-free formats ○ Open-sourced by Google in 2010 ○ BSD-style license ● #protip: great GDL episode on WebM format Brief history of WebP... ● Initial release (2010) ○ Lossy compression for true-color graphics ● October, 2011 ○ Color profile support ○ XMP metadata ● August, 2012 ○ Lossless compression support ○ Transparency (alpha channel) support Now a viable alternative and replacement to JPEG, PNG ● WIP + future... ○ Animation + metadata ○ Encoding performance ○ Better support for ARM and mobile ○ Layer support (3D images) + high color depth images (> 8 bits) WebP vs.
    [Show full text]
  • Life Without Flash
    Life without Flash Are your courses ready? After December 31, 2020, browsers will no longer support the Flash Player. Here is Adobe’s announcement: https://theblog.adobe.com/adobe-flash-update/ What does this mean for HSC Moodle course owners? Most LMS systems and browsers are transitioning away from Flash. You may be at risk of losing your online courses or resources, if they are Adobe Flash only. Moodle courses will need to be republished to alternate formats such as HTML5, MP4, etc. as well as halting any new flash based programs from being uploaded before the December 31st deadline. Many programs have already been getting ready for this change and already offer a conversion to another format. Check with your software support/IT to see how to make this transition easier. How do I find out if my course uses Flash? If you suspect a resource uses Flash, you can simply right-click what you believe to be Flash content to see if a Flash context menu appears: If you are using a browser that blocks Flash content, you may see icons like these: What is the alternative? An alternative solution for course owners is HTML5. HTML5 works with the same multimedia elements as Flash and many web developers have already begun moving to HTML5, which means it‘s supported by most browsers and you won’t need to install anything extra. HTML5-based courses will continue to function as expected. What should I do if my course uses Flash? If Flash courses are published using Flash/HTML5, and designed to fall back to HTML5 when the Flash plugin is removed from the browser, test your courses fall back capability to see whether HTML5 will work as expected.
    [Show full text]
  • Making TIFF Files from Drawing, Word Processing, Powerpoint And
    Making TIFF and EPS files from Drawing, Word Processing, PowerPoint and Graphing Programs In the worlds of electronic publishing and video production programs, the need for TIFF or EPS formatted files is a necessity. Unfortunately, most of the imaging work done in research for presen- tation is done in PowerPoint, and this format simply cannot be used in most situations for these three ends. Files can be generally be saved or exported (by using either Save As or Export under File) into TIFF, PICT or JPEG files from PowerPoint, drawing, word processing and graphing programs—all called vector programs—but the results are often poor in resolution (in Photoshop these are shown as having a resolution of 72dpi when opening the Image Size dialogue box: under Image on the menu select Image Size). Here are four ways to save as TIFF (generally the way in which image files are saved) or EPS (gen- erally the way in which files are saved which contain lines or text): Option 1. Use the Program’s Save As or Export option. If it exists, use the Export or Save As option in your vector program. This only works well when a dialogue box appears so that specific values for height, width and resolution can be typed in (as in the programs Canvas and CorelDraw). Anti-aliasing should be checked. Resolution values of 300 dots per inch or pixels per inch is for images, 600 dpi is for images with text and 1200 dpi is for text, graphs and drawings. If no dialogue box exists to type in these values, go to option 2 - 4.
    [Show full text]
  • Sovereign Wealth Funds 2019 Managing Continuity, Embracing Change
    SOVEREIGN WEALTH FUNDS 2019 MANAGING CONTINUITY, EMBRACING CHANGE SOVEREIGN WEALTH FUNDS 2019 Editor: Javier Capapé, PhD Director, Sovereign Wealth Research, IE Center for the Governance of Change Adjunct Professor, IE University 6 SOVEREIGN WEALTH FUNDS 2019. PREFACE Index 11 Executive Summary. Sovereign Wealth Funds 2019 23 Managing Continuity...Embracing Change: Sovereign Wealth Fund Direct Investments in 2018-2019 37 Technology, Venture Capital and SWFs: The Role of the Government Forging Innovation and Change 55 SWFs in a Bad Year: Challenges, Reporting, and Responses to a Low Return Environment 65 The Sustainable Development Goals and the Market for Sustainable Sovereign Investments 83 SWFs In-Depth. Mubadala: The 360-degree Sovereign Wealth Fund 97 Annex 1. Sovereign Wealth Research Ranking 2019 103 Annex 2. Sovereign Wealth Funds in Spain PREFACE 8 SOVEREIGN WEALTH FUNDS 2019. PREFACE Preface In 2019, the growth of the world economy slowed by very little margin for stimulating the economy to 2.9%, the lowest annual rate recorded since the through the fiscal and monetary policy strategies. subprime crisis. This was a year in which the ele- In any case, the developed world is undergoing its ments of uncertainty that had previously threate- tenth consecutive year of expansion, and the risks ned the stability of the cycle began to have a more of relapsing into a recessive cycle appear to have serious effect on economic expansion. Among these been allayed in view of the fact that, in spite of re- elements, there are essentially two – both of a poli- cord low interest rates, inflation and debt remain at tical nature – that stand out from the rest.
    [Show full text]
  • Adobe Type 1 Font Format Adobe Systems Incorporated
    Type 1 Specifications 6/21/90 final front.legal.doc Adobe Type 1 Font Format Adobe Systems Incorporated Addison-Wesley Publishing Company, Inc. Reading, Massachusetts • Menlo Park, California • New York Don Mills, Ontario • Wokingham, England • Amsterdam Bonn • Sydney • Singapore • Tokyo • Madrid • San Juan Library of Congress Cataloging-in-Publication Data Adobe type 1 font format / Adobe Systems Incorporated. p. cm Includes index ISBN 0-201-57044-0 1. PostScript (Computer program language) 2. Adobe Type 1 font (Computer program) I. Adobe Systems. QA76.73.P67A36 1990 686.2’2544536—dc20 90-42516 Copyright © 1990 Adobe Systems Incorporated. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of Adobe Systems Incorporated and Addison-Wesley, Inc. Printed in the United States of America. Published simultaneously in Canada. The information in this book is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies that may appear in this book. The software described in this book is furnished under license and may only be used or copied in accordance with the terms of such license. Please remember that existing font software programs that you may desire to access as a result of information described in this book may be protected under copyright law. The unauthorized use or modification of any existing font software program could be a violation of the rights of the author.
    [Show full text]
  • EXT EX Product Family Product Family for Occasional Graphics Users and Comparison Comparison Creative Consumers
    TEXT EX Product Family Product Family For occasional graphics users and Comparison Comparison creative consumers For graphics hobbyists and home businesses For occasional For graphics For graphics graphics users and hobbyists and professionals in small Full-featured suite creative consumers home businesses to large businesses for graphics professionals in small to large businesses Main Applications Most Popular CorelDRAW® 2020 Corel PHOTO-PAINT™ 2020 Corel Font Manager™ 2020 PowerTRACE™ (Quick Trace only) (included as part of the CorelDRAW application) CAPTURE™ CorelDRAW.app™ Key Features & Tools (Highlights) Corel AfterShot™ 3 HDR Bevel tool, Shadow tools, Spiral, Smooth and Smear tool, Contour tool Key Features & Tools (Highlights) Clone Tool, Artistic Media Bevel tool, Shadow tools, Spiral, Smooth and Smear tool, Contour tool Key Features & Tools (Highlights) Dimension dockers, Alignment guides Clone Tool, Artistic Media Symmetry drawing mode, Block Shadow tool, Impact tool, Pointillizer, Dimension dockers, Alignment guides PhotoCocktail Barcode Wizard Symmetry drawing mode, Block Professional Print options Duplexing Wizard Shadow tool, Impact tool, Pointillizer, Remove (CMYK features, Composite, Color PhotoCocktail separations, Postscript, Prepress tabs) GPL Ghostscript for enhanced EPS Advanced page layout: left & right master Object styles, Color styles, Color harmonies and PS support pages, custom placeholder text, image rendering above 150dpi Professional Print options (CMYK features, Composite, Color separations, Postscript, Enhanced
    [Show full text]