Hudzilla.org - the homepage of Paul Hudson
Contents > Wish List | Report Bug | About Me ]

11     Multimedia

This is NOT the latest copy of this book; click here for the latest version.

If you have previously only used PHP to work with HTML content, it will come as a nice surprise that working with multimedia content uses almost exactly the same process. It seems that many people just don't realise that PHP is capable of handling much more than non-HTML data, and hopefully this chapter will help shed a great deal of light on this exciting and challenging topic.

Through its extensions, PHP is able to easily handle creating image data in a variety of formats, generating Flash movies, and even generating PDFs - each have their own advantages and disadvantages, and are all in popular use. Having the ability to create custom multimedia content on the fly is very powerful indeed - although outputting content to HTML can do a lot, a picture says a thousand words! For example, by generating multimedia content, we can create dynamic weather forecasts, or user-customised PDFs - the possibilities are endless.

Note that in order to work with multimedia, you must first understand that each type of content, whether it be images, Flash, or PDF, all have their own unique file formats that need to be absolutely precise - you must be careful not to use any text in your multimedia PHP scripts, not even extra blank lines before or after your <?php and ?> tags. The RTF format allows text formatting to be contained using special text encoding characters, and therefore can be manipulated using simple string routines.

Topics covered in this chapter are:

  • The multimedia formats that are available and their advantages

  • Creating basic image formats

  • Working with the rich-text format (RTF)

  • Creating portable document format (PDF) files

  • Working with the Shockwave Flash (SWF) format


Chapter contents

11.1. Brief history of web media
11.1.1. GIF
11.1.2. PNG
11.1.3. JPEG
11.1.4. RTF
11.1.5. PDF
11.1.6. Flash
11.1.7. SVG
11.2. Images
11.2.1. Creating new images: imagecreate(), imagedestroy(), imagecolorallocate()
11.2.2. Choosing a format
11.2.3. Getting arty: imagefilledrectangle()
11.2.4. More shapes: imagecreatetruecolor(), imagefilledellipse(), imagefilledarc(), imageellipse(), imagearc(), and imagerectangle()
11.2.5. Complex shapes: imagefilledpolygon() and imagepolygon()
11.2.6. Outputting text: imagettftext() and imagettfbbox()
11.2.7. Loading existing images: imagecreatefrompng(), imagecreatefromjpeg(), and getimagesize()
11.2.8. Colour and image fills: imagefill(), imagefilltoborder(), and imagesettile()
11.2.9. Adding transparency: imagecolortransparent()
11.2.10. Using brushes: imagesetbrush()
11.2.11. Basic image copying: imagecopy() and imagecopymerge()
11.2.12. Scaling and rotating: imagecopyresized(), imagecopyresampled(), and imagerotate()
11.2.13. Points and lines: imagesetpixel(), imageline(), and imagesetthickness()
11.2.14. Updating the drawing script
11.2.15. Special effects using imagefilter()
11.2.16. Introduction to special effects using simple algorithms
11.2.17. Special FX, Colour reduction: imagetruecolortopalette()
11.2.18. Special FX, Interlacing
11.2.19. Special FX, Screen
11.2.20. Special FX, Greyscale: imagecolorat()
11.2.21. Special FX, Duotone
11.2.22. Special FX, Noise
11.2.23. Special FX, Scatter
11.2.24. Special FX, Pixelate
11.2.25. Special FX, Blur
11.2.26. Special FX, Other special effects
11.2.27. Interlacing an image: imageinterlace()
11.2.28. Getting an image's MIME type: image_type_to_mime_type()
11.2.29. Keeping your files small
11.2.30. Making graphs
11.3. Working with RTF
11.4. Creating PDF documents
11.4.1. There's more than one way to do it
11.4.2. Getting started: pdf_new(), pdf_open_file(), pdf_findfont(), pdf_begin_page(), pdf_setfont(), pdf_show_xy(), pdf_end_page(), pdf_close(), and pdf_delete()
11.4.3. Adding more pages and more style: pdf_setcolor()
11.4.4. Adding imagery: pdf_open_image_file() and pdf_place_image()
11.4.5. PDF special effects: pdf_rotate() and pdf_skew()
11.4.6. Adding document data: pdf_add_note(), pdf_set_info()
11.4.7. PDF Conclusion
11.4.8. Point sizes in real life
11.4.9. ClipPDF interoperability
11.4.10. PDF without a module?
11.5. Creating Flash
11.5.1. A simple movie
11.5.2. Flashy text
11.5.3. Actions
11.5.4. Animation
11.5.5. Flash Conclusion
11.6. Summary
11.7. Exercises
11.8. Further reading
11.9. Next chapter



<< 10.8 Next chapter   11.1 Brief history of web media >>
Table of Contents
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.



My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!



Top-right shadow
 
Bottom-left shadow Bottom shadow

Comments from other readers
ffmpeg.php@gmail.com - 24 Jul 2008

Hi, I've written a php extension that allows php to work with movie files. Highlights are:

* grab frames from a movie and manipulate them with PHP's gd image functions.
* get framerate, duration, bitrate and many other parameters of movies and sound files.
* get info about mp3 and other sound files.
* create animated GIFs from a series of movie frame or gd images.

Check it out at http://ffmpeg-php.sourceforge.net/

Please consider adding a mention of it in your book. If you need help or examples, let me know.

Thanks!
-Todd Kirby



Add comment
Please note that by posting a comment here you are committing it to the public domain. This is important so that others can make use of your code themselves, and also so that I can incorporate helpful notes directly into the main text. Comments are limited to 2000 characters in length.

If you are reporting an error in the content, please tell me directly.

Your name/email address:
Your comment:
 
Now, in order to verify that you're a real person, please answer this simple question: what is eight plus one?
The answer is:
(please write in
numbers, eg 19)


Top-right shadow
 
Bottom-left shadow Bottom shadow