I'm using Imagemagik in PHP codeigniter, I want to allow all special character, smiley etc.. but it's not working. Can anyone help me how to do this. Here is my code.
$textonimage = $this->input->post('textonimage');
if(!empty($background)){
$string = $textonimage;
$smart_wordwrap_info = smart_wordwrap($string, 20);
$height_1 = substr_count( $smart_wordwrap_info, "\n" );
$color_string_length = strlen($colors);
if($color_string_length > 7){
$colors_result = substr($colors, 3);
$colors = '#'.$colors_result;
}
$height_2 = $height_1+1;
$height_3 = $height_2-2;
$height_4 = 30*$height_3;
$height = 200+$height_4;
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( $colors );
$image->newImage(350, $height, $pixel);
$image->setImageFormat('png');
$image->writeImage(FCPATH.'uploads/post-image/my_output.png');
$process_file_path = FCPATH.'uploads/post-image/my_output.png';
$target_file_name = mt_rand(10000,99999).'.png';
$target_path = FCPATH.('uploads/post-image/'.$target_file_name);
$target_path_1 = base_url().'uploads/post-image/'.$target_file_name;
exec("convert ".$process_file_path." -gravity center -fill white -font Corsiva -pointsize 30 -interline-spacing 40 -annotate +0+0 '".$smart_wordwrap_info."' ".$target_path);
$upload_image[] = $target_path_1;
#unlink($process_file_path);
}
I tried something like this, but it's not working.
exec("convert ".$process_file_path." -gravity center -fill white -font Corsiva -pointsize 30 -interline-spacing 40 -annotate +0+0 '".($smart_wordwrap_info |sed "s/'/\'/g)."' ".$target_path);
Related
I want to center text over an image, horizontal and vertical. And let it automatically fit (unless what the content is).
When I use the command line, this command works almost perfectly (needs some little finetuning):
magick image.jpg -gravity Center -size 320x140 caption:'This text is resized to best fill the space given.' -compose over -composite ouput.jpg
However, now I want to achieve the same with PHP, but the text does not resize over multiple lines, so I am doing something wrong.
The script I've created so far:
$text = 'This text is resized to best fill the space given.';
$width = 600;
$height = 600;
$textBackground = new ImagickPixel('transparent');
$textColor = new ImagickPixel('#000');
$gradient = new Imagick('image.jpg');
$image = new Imagick();
$image->newImage($width, $height, $textBackground);
$gradient->setImageColorspace($image->getImageColorspace());
$draw = new ImagickDraw();
//$draw->setFillColor($textColor);
$draw->setFontSize( 36 );
$draw->setFont("Alegreya.ttf");
$draw->setGravity (Imagick::GRAVITY_CENTER);
$image->annotateImage($draw, 0, 0, 0, $text);
$gradient->compositeImage($image, Imagick::COMPOSITE_OVER, 0, 0);
$gradient->setImageFormat('jpg');
header('Content-type: image/jpg');
echo $gradient;
The output this generates:
I need this line:
magick "input.jpg" -fuzz 4% -transparent white -background white -alpha remove -alpha off -quality 85% "result.jpg"
to PHP imagick:
$img = new Imagick($root . '/testall/imagemagick/input.jpg');
// ???
$img->setImageFormat('jpg');
$img->setImageCompressionQuality(85);
$img->writeImage($root . '/testall/imagemagick/result.jpg');
and I can't find fuzz in https://www.php.net/manual/de/book.imagick.php to even start with.
Please help
You might be able to use: Imagick::transparentPaintImage:
$img = new Imagick($root . '/testall/imagemagick/input.jpg');
$fuzz = 4 * \Imagick::getQuantum(); // Copied from the example?
$img->transparentPaintImage('white', 0, $fuzz, false);
...
Well I tried around with andlrc answer and this is the working result:
$img = new Imagick('input.jpg');
$fuzz = Imagick::getQuantum() * ($whitePercentage / 100);
$BackgroundColor = "rgb(255, 255, 255)";
$img->setImageFormat('png');
$img->transparentPaintImage($BackgroundColor, 0, $fuzz, false);
$img->setimagebackgroundcolor('white');
$img = $img->mergeImageLayers( imagick::LAYERMETHOD_FLATTEN );
$img->setImageFormat('jpg');
$img->setImageCompressionQuality($qualy);
$img->writeImage($root . '/testall/imagemagick/result.jpg');
How to add one or more gif animations.
// Create image instances
$dest = imagecreatefromgif('php.gif');
$src = imagecreatefromgif('php.gif');
// Copy and merge
imagecopymerge($dest, $src, 10, 10, 0, 0, 100, 47, 75);
// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);
imagedestroy($dest);
imagedestroy($src);
The code above is not working.
http://www.imagemagick.org/Usage/anim_mods/
$str = "Mary Had A Little Lamb and She LOVED It So";
echo $str = str_replace(' ','',(strtolower($str)));
exec('convert alphabets/1/a.gif -repage 92x62 -coalesce null: ( alphabets/1/b.gif -coalesce ) -geometry +46+0 -layers Composite out.gif');
list($width, $height) = getimagesize('alphabets/1/e.gif');
list($out_width, $out_height) = getimagesize('out.gif');
$width1 = $out_width+$width;
exec('convert out.gif -repage '.$width1.'x'.$height.' -coalesce null: ( alphabets/1/e.gif -coalesce ) -geometry +'.$out_width.'+0 -layers Composite out1.gif');
I try this:
$path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'];
$image = imagecreatefromstring(file_get_contents($path));
$w = imagesx($image);
$h = imagesy($image);
$centerX=round($w/4);
$centerY=round($h/2);
$watermark = imagecreatefrompng('lool-face.png');
$ww = imagesx($watermark);
$wh = imagesy($watermark);
imagecopy($image, $watermark, $centerX, $centerY, 0, 0, $ww, $wh);
eregi('\.(gif|jpeg|jpg|png)$',$path,$regs);
switch( $regs[1] ) {
case 'gif':
header('Content-type: image/gif');
imagegif($image);
break;
but this don't working, the images is curdle.
And try this:
shell_exec('for i in sphere*.gif; do convert $i -font Arial -pointsize 20 \
-draw "gravity south \
fill black text 0,12 \'Copyright\' \
fill white text 1,11 \'Copyright\' " \
wmark_$i; done');
shell_exec("convert -delay 20 -loop 0 wmark_sphere*.gif animatespheres.gif");
$f = fopen("animatespheres.gif", 'rb');
fpassthru($f);
fclose($f);
This code does not work I do not know why it does not.
We wish you a directory where there Gif htaccess can do it in gifs watermarking
This class could be your solution:
PHP Classes transparent watermark
Take a look at the link below. I have done the same thing in php. I hope that this will helps you.
https://dl.dropboxusercontent.com/u/58146160/watermark%20image.rar
I need a function that adds a watermark to an animated gif. How I can do that with PHP and ImageMagick?
This is my code, but it doesn't work.
function IMagickWatermark($sf, $sfDest, $sfLogo, $sGravity='southeast'){
//$sCmd = "composite -compose bumpmap -gravity $sGravity $sfLogo \"$sf\" $sfDest";
$sCmd = "convert \"$sf\" -coalesce -gravity south -draw 'image over 0,0 0,0 \"$sfLogo\"' \"$sfDest\"";
exec($sCmd);
return 1;
}
$sf = $_SERVER['DOCUMENT_ROOT']."/test/source.gif";
$sfDest = $_SERVER['DOCUMENT_ROOT']."/test/dest.gif";
$sfLogo = $_SERVER['DOCUMENT_ROOT']."/test/logowithtext.gif";
IMagickWatermark($sf, $sfDest, $sfLogo, $sGravity='SouthEast');
Try this:
$animation = ani.gif;
$watermark = logo.png;
$watermarked_animation = "morph.gif";
$cmd = " $animation -coalesce -gravity South ".
" -geometry +0+0 null: $watermark -layers composite -layers optimize ";
exec("convert $cmd $watermarked_animation ");
<?php
shell_exec('for i in sphere*.gif; do convert $i -font Arial -pointsize 20 \
-draw "gravity south \
fill black text 0,12 \'Copyright\' \
fill white text 1,11 \'Copyright\' " \
wmark_$i; done');
shell_exec("convert -delay 20 -loop 0 wmark_sphere*.gif animatespheres.gif");
$f = fopen("animatespheres.gif", 'rb');
fpassthru($f);
fclose($f);
?>
if you need to debug, remove the fopen,fpassthru,fclose lines and add echo's for the shell_execs.