- ProcessWire Support Forums
- → Viewing Profile: Posts: summer
Community Stats
- Group Members
- Active Posts 6
- Profile Views 335
- Member Title Newbie
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Not Telling
5
Neutral
User Tools
Friends
summer hasn't added any friends yet.
Latest Visitors
Posts I've Made
In Topic: Instagram module
14 August 2012 - 07:45 PM
I have created a github repository for it here https://github.com/s...ireImageEffects
In Topic: Instagram module
10 August 2012 - 07:14 AM
Hello again.
I kinda got this working with a few different effects.
I had to implement a weird fix so the functions don't get called twice (notice the counter used to check if even or uneven) I just can't figure out why that is. If somebody could help that would be great!
home.php
FieldtypeImageEffects.module
Outputs the attached image
I kinda got this working with a few different effects.
I had to implement a weird fix so the functions don't get called twice (notice the counter used to check if even or uneven) I just can't figure out why that is. If somebody could help that would be great!
home.php
<?php
/**
* Home template
*
*/
include("./head.inc");
foreach($homepage->images as $img)
{
echo("Original</br>");
$image =$img->size(400, 400);
echo "<img id='photo' src='{$image->url}' alt='{$image->description}' width='{$image->width}' height='{$image->height}' /><br/>";
echo("Gotham</br>");
$image =$img->size(400, 400)->fx(FieldtypeImageEffects::GOTHAM, 5, 1);
echo "<img id='photo' src='{$image->url}' alt='{$image->description}' width='{$image->width}' height='{$image->height}' /><br/>";
echo("Toaster</br>");
$image = $img->size(400, 400)->fx(FieldtypeImageEffects::TOASTER, 1.2);
echo "<img id='photo' src='{$image->url}' alt='{$image->description}' width='{$image->width}' height='{$image->height}' /><br/>";
echo("Nashville</br>");
$image = $img->size(400, 400)->fx(FieldtypeImageEffects::NASHVILLE, 1.2);
echo "<img id='photo' src='{$image->url}' alt='{$image->description}' width='{$image->width}' height='{$image->height}' /><br/>";
echo("Custom frame</br>");
$image = $img->size(400, 400)->fx(FieldtypeImageEffects::NASHVILLE, 1.2)->fx(FieldtypeImageEffects::FRAME, "polaroid01.png");
echo "<img id='photo' src='{$image->url}' alt='{$image->description}' width='{$image->width}' height='{$image->height}' /><br/>";
break;
}
include("./foot.inc");
FieldtypeImageEffects.module
<?php
class FieldtypeImageEffects extends FieldtypeImage implements Module
{
const GOTHAM = "fxGotham";
const TOASTER = "fxToaster";
const NASHVILLE = "fxNashville";
const FRAME = "fxFrame";
private $counter = 0;
public static function getModuleInfo()
{
return array
(
'title' => 'Image Effects',
'version' => 001,
'summary' => 'Add effects to images',
'href' => 'http://www.persommer.com',
);
}
public function init()
{
$this->addHook('Pageimage::fx', $this, 'fx');
}
public function fx(HookEvent $event)
{
$this->counter++;
if ($this->counter % 2)
{
switch ($event->arguments[0])
{
case $this::GOTHAM:
$event->return = $this->fxGotham($event);
break;
case $this::TOASTER:
$event->return = $this->fxToaster($event);
break;
case $this::NASHVILLE:
$event->return = $this->fxNashville($event);
break;
case $this::FRAME:
$event->return = $this->fxFrame($event);
break;
default:
$event->return = $event->object;
}
}
else
{
//echo $this->counter . " is even<br>";
}
}
private function fxGotham(HookEvent $event)
{
isset($event->arguments[1]) ? $intColorize = $event->arguments[1] : $intColorize = 20;
isset($event->arguments[2]) ? $floatGamma = $event->arguments[2] : $floatGamma = 0.5;
$prefix = $this->sanitizeFilename("_" . $event->arguments[0] . $intColorize . $floatGamma);
$img = $event->object;
$imgBaseNameNew = $this->appendToFileName($img->basename, $prefix);
$imgPath = $img->pagefiles->path . $img->basename;
$imgPathNew = $img->pagefiles->path . $imgBaseNameNew;
$this->execute("convert '$imgPath' -modulate 120,10,100 -fill '#222b6d' -colorize $intColorize -gamma $floatGamma -contrast -contrast '$imgPathNew'");
//!is_file($imgPathNew) ? $this->execute($strExe) : false;
$event->object->setFilename($imgBaseNameNew);
return $event->object;
// $pageimage = clone $event->object;
// $pageimage->setFilename($imgBaseNameNew);
// $pageimage->setOriginal($event->object);
// return $pageimage;
}
private function fxToaster(HookEvent $event)
{
isset($event->arguments[1]) ? $floatGamma = $event->arguments[1] : $floatGamma = 1.2;
$width = $event->object->width();
$height = $event->object->height();
$prefix = $this->sanitizeFilename("_" . $event->arguments[0] . $floatGamma);
$img = $event->object;
$imgBaseNameNew = $this->appendToFileName($img->basename, $prefix);
$imgPath = $img->pagefiles->path . $img->basename;
$imgPathNew = $img->pagefiles->path . $imgBaseNameNew;
$this->colortone($imgPath, $imgPathNew, '#330000', 100, 0);
$this->execute("convert '$imgPathNew' -modulate 150,80,100 -gamma $floatGamma -contrast -contrast '$imgPathNew'");
$this->vignette($imgPathNew, $imgPathNew, $width, $height, 'none', 'LavenderBlush3');
$this->vignette($imgPathNew, $imgPathNew, $width, $height, '#ff9966', 'none');
//!is_file($imgPathNew) ? $this->execute($strExe) : false;
$event->object->setFilename($imgBaseNameNew);
return $event->object;
}
private function fxNashville(HookEvent $event)
{
isset($event->arguments[1]) ? $floatGamma = $event->arguments[1] : $floatGamma = 1.2;
$width = $event->object->width();
$height = $event->object->height();
$prefix = $this->sanitizeFilename("_" . $event->arguments[0] . $floatGamma);
$img = $event->object;
$imgBaseNameNew = $this->appendToFileName($img->basename, $prefix);
$imgPath = $img->pagefiles->path . $img->basename;
$imgPathNew = $img->pagefiles->path . $imgBaseNameNew;
$this->colortone($imgPath, $imgPathNew, '#222b6d', 100, 0);
$this->colortone($imgPath, $imgPathNew, '#f7daae', 100, 1);
$this->execute("convert '$imgPathNew' -contrast -modulate 100,150,100 -auto-gamma '$imgPathNew'");
$this->frame($imgPathNew, $imgPathNew, "grunge01.png", $width, $height);
//!is_file($imgPathNew) ? $this->execute($strExe) : false;
$event->object->setFilename($imgBaseNameNew);
return $event->object;
}
private function fxFrame(HookEvent $event)
{
isset($event->arguments[1]) ? $frameFile = $event->arguments[1] : $framefile = "grunge01.png";
$width = $event->object->width();
$height = $event->object->height();
$path_parts = pathinfo($frameFile);
$prefix = $this->sanitizeFilename("_" . $path_parts['filename']);
$img = $event->object;
$imgBaseNameNew = $this->appendToFileName($img->basename, $prefix);
$imgPath = $img->pagefiles->path . $img->basename;
$imgPathNew = $img->pagefiles->path . $imgBaseNameNew;
$this->frame($imgPath, $imgPathNew, $frameFile, $width, $height);
//!is_file($imgPathNew) ? $this->execute($strExe) : false;
$event->object->setFilename($imgBaseNameNew);
return $event->object;
}
private function execute($command)
{
// echo("COMMAND INPUT: " . $command . "<br>");
$out = array();
putenv("PATH=" . $_ENV["PATH"] . ":/opt/local/bin");
exec($command . " 2>&1", $out);
// echo("COMMAND OUTPUT: " . print_r($out, true) . "<br>");
}
private function appendToFileName($filename, $prefix)
{
if ($prefix != "")
{
$path_parts = pathinfo($filename);
return $path_parts['filename'] . $prefix . "." . $path_parts['extension'];
}
return "errorprefix-" . $filename;
}
private function sanitizeFilename($strFilename)
{
$strFilename = str_replace(".", "", $strFilename);
return $strFilename;
}
public function colortone($input, $inputNew, $color, $level, $type = 0)
{
$args[0] = $level;
$args[1] = 100 - $level;
$negate = $type == 0 ? '-negate' : '';
$strColortone = "convert '$input' \( -clone 0 -fill '$color' -colorize 100% \) \( -clone 0 -colorspace gray $negate \) -compose blend -define compose:args=$args[0],$args[1] -composite '$inputNew'";
$this->execute($strColortone);
}
public function border($input, $color = 'black', $width = 20)
{
$this->execute("convert $input -bordercolor $color -border " . $width . "x" . $width . " $input");
}
public function frame($input, $inputNew, $frame, $width, $height)
{
$strFramePath = $_SERVER['DOCUMENT_ROOT'] . "/site/modules/frames/" . $frame;
//echo ("DOC LOCATION: " . $strFramePath . "<br>");
$strExe = "convert '$input' \( '$strFramePath' -resize {$width}x{$height}! -unsharp 1.5×1.0+1.5+0.02 \) -flatten '$inputNew'";
//echo ("EXE: " . $strExe . "<br>");
$this->execute($strExe);
}
public function vignette($input, $inputNew, $width, $height, $color_1 = 'none', $color_2 = 'black', $crop_factor = 1.5)
{
$crop_x = floor($width * $crop_factor);
$crop_y = floor($height * $crop_factor);
$strVignette = "convert \( '$input' \) \( -size {$crop_x}x{$crop_y} radial-gradient:$color_1-$color_2 -gravity center -crop {$width}x{$height}+0+0 +repage \) -compose multiply -flatten '$inputNew'";
$this->execute($strVignette);
}
}
Outputs the attached image
In Topic: Instagram module
08 August 2012 - 01:59 PM
yes, but what i wanted to do was actually modify the original object. this is also possible by calling
so it's basically working the way i want it to. except for some reason it seems "kelvin()" gets called twice. will try to figure that out later.
thanx
$event->object->setFilename($imgBaseNameNew);
so it's basically working the way i want it to. except for some reason it seems "kelvin()" gets called twice. will try to figure that out later.
thanx
In Topic: Instagram module
08 August 2012 - 12:33 PM
Hey again and thanks for the replies! I had some trouble getting image magic to work on my mac, but now all is good.
My question is now: how do I update the data on the image object so it points towards the modified file?
still outputs the same as
Code so far:
My question is now: how do I update the data on the image object so it points towards the modified file?
$image->size(232, 176)->kelvin(55)->url
still outputs the same as
$image->size(232, 176)->url
Code so far:
<?php
class FieldtypeImageEffects extends FieldtypeImage implements Module
{
public $url;
public static function getModuleInfo()
{
return array
(
'title' => 'Image Effects',
'version' => 001,
'summary' => 'Add effects to images',
'href' => 'http://www.persommer.com',
);
}
public function init()
{
$this->addHook('Pageimage::kelvin', $this, 'kelvin');
}
public function kelvin(HookEvent $event)
{
$prefix = "kelvin";
$img = $event->object;
$imgPath = $img->pagefiles->path . "" . $img->basename;
$imgPathNew = $img->pagefiles->path . "kelvin_" . $img->basename;
// $imgUrl = $img->pagefiles->url . $prefix . "_" . $img->basename;
// $event->object->setUrl($imgUrl);
$strExe = "convert '$imgPath' -modulate 120,10,100 -fill '#222b6d' -colorize 20 -gamma 0.5 -contrast -contrast '$imgPathNew'";
if (is_file($imgPathNew))
{
// echo("file exists: <br>");
}
else
{
// echo("converting file: <br>");
$this->execute($strExe);
}
$this->url = "HEHEHE";
$event->return = $event->object;
}
public function execute($command)
{
// echo("COMMAND INPUT: " . $command . "<br>");
$out = array();
putenv("PATH=" . $_ENV["PATH"] . ":/opt/local/bin");
exec($command . " 2>&1", $out);
// echo("COMMAND OUTPUT: " . print_r($out, true) . "<br>");
}
}
In Topic: Instagram module
07 August 2012 - 12:40 PM
hello and thanks to both of you. I have taken your suggestions into consideration but have run into a development block.
I tried to install my module and am now greeted with an error message:
Fatal error: Class 'FieldtypeImage' not found in /Users/Development/persommer html/site/modules/FieldtypeImageEffects.module on line 2
And I can't make it go away :-/
I tried to install my module and am now greeted with an error message:
Fatal error: Class 'FieldtypeImage' not found in /Users/Development/persommer html/site/modules/FieldtypeImageEffects.module on line 2
And I can't make it go away :-/
<?php
class FieldtypeImageEffects extends FieldtypeImage implements Module
{
public static function getModuleInfo()
{
return array
(
'title' => 'Image Effects',
'version' => 001,
'summary' => 'Add effects to images',
'href' => 'http://www.persommer.com',
'singular' => true,
'autoload' => true,
);
}
public function init()
{
}
}
- ProcessWire Support Forums
- → Viewing Profile: Posts: summer
- Privacy Policy





Find content