Reputation: 123
I am using ImageMagic for a project, Since i use windows i installed wamp, i want to convert some text into images, insert effects and make an animated gif out of it, i tried various folder options finally ended up with this, which does not work as well. Can someone help? the code which i am using right now is
"D:\Program Files\EasyPHP\data\localweb\imgmgk\convert" -background "" -fill "#000" -font Arial -pointsize 12 label:" hi casino" "D:\Program Files\EasyPHP\data\localweb\files\bum.jpg"a link to ImageMagick http://www.imagemagick.org/script/convert.php
Upvotes: 0
Views: 460
Reputation: 123
Sorted! Thanks a lot for helping me out. There was one file which i could not get from the tutorial url, here is the alternate link. http://windows.php.net/downloads/pecl/releases/imagick/3.1.2/php_imagick-3.1.2-5.5-ts-vc11-x86.zip
Upvotes: 0
Reputation: 3037
Try Imagick,
Imagick is a native php extension to create and modify images using the ImageMagick API
.
ImageMagick is a software suite to create, edit, and compose bitmap images.. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF.
By using this, we have an example.
whirlyGif
function lerp($t, $a, $b)
{
return $a + ($t * ($b - $a));
}
class Dot
{
public function __construct($color, $sequence, $numberDots, $imageWidth, $imageHeight)
{
$this->color = $color;
$this->sequence = $sequence;
$this->numberDots = $numberDots;
$this->imageWidth = $imageWidth;
$this->imageHeight = $imageHeight;
if ($this->numberDots < 0) {
$this->numberDots = 0;
}
}
public function calculateFraction($frame, $maxFrames, $timeOffset, $phaseMultiplier, $phaseDivider)
{
$frame = -$frame;
$totalAngle = 2 * $phaseMultiplier;
$fraction = ($frame / $maxFrames * 2);
$fraction += $totalAngle * ($this->sequence / $this->numberDots);
if ($phaseDivider != 0) {
$fraction += (($this->sequence)) / ($phaseDivider);
}
$fraction += $timeOffset;
while ($fraction < 0) {
//fmod does not work 'correctly' on negative numbers
$fraction += 64;
}
$fraction = fmod($fraction, 2);
if ($fraction > 1) {
$unitFraction = 2 - $fraction;
}
else {
$unitFraction = $fraction;
}
return $unitFraction * $unitFraction * (3 - 2 * $unitFraction);
}
public function render(\ImagickDraw $draw, $frame, $maxFrames, $phaseMultiplier, $phaseDivider)
{
$innerDistance = 40;
$outerDistance = 230;
$sequenceFraction = $this->sequence / $this->numberDots;
$angle = 2 * M_PI * $sequenceFraction;
$trailSteps = 5;
$trailLength = 0.1;
$offsets = [
100 => 0,
];
for ($i=0; $i<=$trailSteps; $i++) {
$key = intval(50 * $i / $trailSteps);
$offsets[$key] = $trailLength * ($trailSteps - $i) / $trailSteps;
}
//TODO - using a pattern would make the circles look more natural
//$draw->setFillPatternURL();
foreach ($offsets as $alpha => $offset) {
$distanceFraction = $this->calculateFraction($frame, $maxFrames, $offset, $phaseMultiplier, $phaseDivider);
$distance = lerp($distanceFraction, $innerDistance, $outerDistance);
$xOffset = $distance * sin($angle);
$yOffset = $distance * cos($angle);
$draw->setFillColor($this->color);
$draw->setFillAlpha($alpha / 100);
$xOffset = $xOffset * $this->imageWidth / 500;
$yOffset = $yOffset * $this->imageHeight / 500;
$xSize = 4 * $this->imageWidth / 500;
$ySize = 4 * $this->imageHeight / 500;
$draw->circle(
$xOffset,
$yOffset,
$xOffset + $xSize,
$yOffset + $ySize
);
}
}
}
function whirlyGif($numberDots, $numberFrames, $loopTime, $backgroundColor, $phaseMultiplier, $phaseDivider)
{
$aniGif = new \Imagick();
$aniGif->setFormat("gif");
$width = 500;
$height = $width;
$numberDots = intval($numberDots);
if ($numberDots < 1) {
$numberDots = 1;
}
$maxFrames = $numberFrames;
$frameDelay = ceil($loopTime / $maxFrames);
$scale = 1;
$startColor = new \ImagickPixel('red');
$dots = [];
for ($i=0; $i<$numberDots; $i++) {
$colorInfo = $startColor->getHSL();
//Rotate the hue by 180 degrees
$newHue = $colorInfo['hue'] + ($i / $numberDots);
if ($newHue > 1) {
$newHue = $newHue - 1;
}
//Set the ImagickPixel to the new color
$color = new \ImagickPixel('#ffffff');
$colorInfo['saturation'] *= 0.95;
$color->setHSL($newHue, $colorInfo['saturation'], $colorInfo['luminosity']);
$dots[] = new Dot($color, $i, $numberDots, $width, $height);
}
for ($frame = 0; $frame < $maxFrames; $frame++) {
$draw = new \ImagickDraw();
$draw->setStrokeColor('none');
$draw->setFillColor('none');
$draw->rectangle(0, 0, $width, $height);
$draw->translate($width / 2, $height / 2);
foreach ($dots as $dot) {
/** @var $dot Dot */
$dot->render($draw, $frame, $maxFrames, $phaseMultiplier, $phaseDivider);
}
//Create an image object which the draw commands can be rendered into
$imagick = new \Imagick();
$imagick->newImage($width * $scale, $height * $scale, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->setImageDispose(\Imagick::DISPOSE_PREVIOUS);
//Render the draw commands in the ImagickDraw object
//into the image.
$imagick->drawImage($draw);
$imagick->setImageDelay($frameDelay);
$aniGif->addImage($imagick);
$imagick->destroy();
}
$aniGif->setImageFormat('gif');
$aniGif->setImageIterations(0); //loop forever
$aniGif->mergeImageLayers(\Imagick::LAYERMETHOD_OPTIMIZEPLUS);
header("Content-Type: image/gif");
echo $aniGif->getImagesBlob();
}
The output will be
You can find more examples here
Upvotes: 1