Table of Contents

Automation Status

Questions:

  • What fonts are used? TTF or PS? Need copies for server.
  • RGB or CMYK?
  • Print resolution → 300dpi?
  • What configuration of user supplied images should be accepted per template? {x| x? 1-3} → may be easier to pregenerate the shadows…
  • API? e.g. call http://tcmaker.org/portfolio.php?name=John&title=Doe&description=BlahBlahBlah to automatically generate the image which can be consumed by your app, browser, etc.

Cairo

Cairo is a 2D vector graphics library that implements PS, PNG, PDF, SVG, and other file formats that is used in such products as GTK+, Firefox, Chrome, GnuPlot. PECL/Cairo is a PECL extension (PHP Extension Community Library) that “binds” the low level Cairo functionality into something easier to work with in PHP. The extension is far from complete, but it may just do what we need for automating the portfolio pages. I've got it setup and outputting PNG and SVG images. Unfortunately, it was a pain in the butt to get setup as there's not much useful documentation on the extension. Here's my notes on getting it setup:

  • apt-get install php-pear php5-dev pkg-config libcairo2-dev make
  • pecl install channel://pecl.php.net/cairo-0.2.0
  • echo 'extension=cairo.so'>> /etc/php5/apache2/php.ini

I am unsure if apache needs to be restarted, but if it does run “service apache2 restart”

Here's the code I have so far:

cairo.php
<?php
header('Content-type: image/svg+xml');
 
// php://output outputs to the page
$v = new CairoSvgSurface('php://output', 400, 400);
 
// Context is "tool" that "paints" the Surface
$c = new CairoContext($v);
$c->fill();
 
// Nuance: x  {R,G,B} | 0 <= x <= 1
$c->setSourceRGB(1, 0, 0);
$c->setLineWidth(50);
$c->arc(200, 200, 100, 0, 2 * M_PI);
$c->stroke();
 
$c->setSourceRGB(0, 0, 0.6);
$c->rectangle(0, 160, 400, 75);
$c->fill();
 
$v->finish();
?>

(I now cannot find the site that had this example outputting a PNG image, so just know I ripped it offa somewhere and modified it to output an SVG image)

cairo.svg
Try zooming in all the way… NO PIXELLATION!!!

Opening it up in a text editor will give this:

cairo.svg
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="400pt" height="400pt" viewBox="0 0 400 400" version="1.1">
<g id="surface0">
<path style="stroke: none; fill-rule: nonzero; fill: rgb(0, 0, 0); fill-opacity: 1;" d=""/>
<path style="fill: none; stroke-width: 50; stroke-linecap: butt; stroke-linejoin: miter; stroke: rgb(255, 0, 0); stroke-opacity: 1; stroke-miterlimit: 10;" d="M 300 200 C 300 255.226562 255.226562 300 200 300 C 144.773438 300 100 255.226562 100 200 C 100 144.773438 144.773438 100 200 100 C 255.226562 100 300 144.773438 300 200 "/>
<path style="stroke: none; fill-rule: nonzero; fill: rgb(0, 0, 153); fill-opacity: 1;" d="M 0 160 L 400 160 L 400 235 L 0 235 Z M 0 160 "/>
</g>
</svg>

Links, References, Etc.

GD

Being depreciated except for use with raster images.

  • apt-get install php5-gd
<?php
header('Content-type: image/png');
$font = './Lucida Sans Demibold Roman.ttf';
$font_size = 10;
 
$fp_port0 = '/var/www/test/tcm-portfolio.png';
 
$template = imagecreatefrompng($fp_port0);
 
$width = imagesx($template);
$height = imagesy($template);
 
// Create a new 32-bit color canvas because importing
//   a PNG limits to its palette of colors
$canvas = imagecreatetruecolor($width, $height);
 
// Copy the template to the canvas and destroy
imagecopy($canvas, $template, 0, 0, 0, 0, $width, $height);
imagedestroy($template);
 
$black = imagecolorallocate($canvas,   0,   0,   0);
$red   = imagecolorexact($canvas, 168,   40,   47);
 
imagefttext($canvas, $font_size, 0, 80, 420, $red, $font, "Maker");
imagefttext($canvas, $font_size, 0, 160, 420, $black, $font, "John Doe");
imagefttext($canvas, $font_size, 0, 80, 440, $red, $font, "Title");
imagefttext($canvas, $font_size, 0, 160, 440, $black, $font, "Automated portfolio page creator");
 
// Display on page
imagepng($canvas);
imagedestroy($canvas);
?>

To Do

  • webform
  • database
Print/export
Toolbox