Appreciation
First of all I would like to say Thank You for making such a fantastic back-end. In my ten years of web development it's the first one to actually make sense to me. When I used to develop in Flash I was searching every where for a back-end that would just let me output my data as xml without the hassle of learning a new "language" or syntax, or messing with settings directly in the back-end itself. For my current portfolio and some other sites I ended up using Drupal with some plugins for managing the data and then just dug in to the database directly, pulling out whatever i needed. It wasn't easy, but it was easier than learning how to make an actual plugin that did the same.
With process wire I realize now I could have saved weeks of development, had I known of it's existence. It was so easy to get into that I basically just sad down a few hours one day to get familiar with the UI and I have only had use for the cheat sheet ever since. This stuff is build in a very logical way and without unneeded complexity. I can see a lot of thought / experience has gone into this, and I really appreciate you letting us use it!
Question
I have some ideas for new modules that I would like to build. They would add some extra functionality to the core functions of Processwire. One is to implement getID3() (http://getid3.sourceforge.net/) to get the extra data in mp3s like $fileMp3->composer for example.
The other one is to add extra image functionality on both the front- and back-end using imagemagick. I'm updating my portfolio to an html5 version and it's going to have a worn down/outdoor look, and therefore I'd like to add some Instagram type of effects to certain images (http://net.tutsplus....lters-with-php/).
On the back-end I would like to add options for adding image effects when the image has been uploaded. I would like to keep the original while the modified Image is used by the front-end. Ideally it would be a drop down with some predefined effects while having the option to add more than one effect.
Next would be to extend the Image with more options, just in the same way resize works. For example $fileImage->resize(150,150)->kelvin(75, "#4499ff")
I'll post what I came up with so far. It's inspired mainly by the tutsplus article and it contains obvious errors, but it's more to give you an idea of what I want to achieve.
I looked for an Image class to add a hook to - in the same way that resize works, but I couldn't really find out how it was put together. I also don't quite understand why this module shows up under an "Image" section as I didn't define it anywhere (see attached image).
I'm not asking for finished code here, but looking for guidance as http://processwire.com/api/modules/ and the hello_world.module don't tell me what I want to know. Or maybe I'm looking in the wrong place?
Anyway, here's the code so far. Any tips would be greatly appreciated! ( And sorry for the wall of text
<?php
class ImageInstagram extends WireData implements Module
{
public $_image = NULL;
public $_output = NULL;
public $_prefix = 'IMG';
private $_width = NULL;
private $_height = NULL;
private $_tmp = NULL;
public static function getModuleInfo()
{
return array(
// The module'ss title, typically a little more descriptive than the class name
'title' => 'Image Instagram Effects',
// version: major, minor, revision, i.e. 100 = 1.0.0
'version' => 003,
// summary is brief description of what this module is
'summary' => 'Add InstaGram effects to images',
// Optional URL to more information about the module
'href' => 'http://www.processwire.com',
// singular=true: indicates that only one instance of the module is allowed.
// This is usually what you want for modules that attach hooks.
'singular' => true,
// autoload=true: indicates the module should be started with ProcessWire.
// This is necessary for any modules that attach runtime hooks, otherwise those
// hooks won't get attached unless some other code calls the module on it's own.
// Note that autoload modules are almost always also 'singular' (seen above).
'autoload' => true,
);
}
public function init()
{
$this->addHook('Images::kelvin', $this, 'kelvin');
}
public function kelvin($event)
{
$this->tempfile();
$this->execute("convert( $this->_tmp -auto-gamma -modulate 120,50,100 ) ( -size {$this->_width}x{$this->_height} -fill 'rgba(255,153,0,0.5)' -draw 'rectangle 0,0 {$this->_width},{$this->_height}' ) -compose multiply $this->_tmp");
$this->frame($this->_tmp, __FUNCTION__);
$this->output();
}
public function tempfile()
{
# copy original file and assign temporary name
$this->_tmp = $this->_prefix . rand();
copy($this->_image, $this->_tmp);
}
public function frame($input, $frame)
{
$this->execute("convert $input ( '$frame' -resize {$this->_width}x{$this->_height}! -unsharp 1.5×1.0+1.5+0.02 ) -flatten $input");
}
public function execute($command)
{
# remove newlines and convert single quotes to double to prevent errors
$command = str_replace(array("\n", "'"), array('', '"'), $command);
$command = escapeshellcmd($command);
# execute convert program
exec($command);
}
public function output()
{
# rename working temporary file to output filename
rename($this->_tmp, $this->_output);
}
}












