I am trying to generate image with background and pattern like in this image.
Currently I have this command
magick convert \
\( \
-size 512x512 \
-define "gradient:vector=0,0 0,720" "gradient:#5DA2C2-#C70AA0" \
\) \
\( \
-size 4x4 xc:white -alpha transparent \
-channel alpha -fx "(1-min(1,(j+1)%2)) * 0.1" \
-write mpr:lines1 +delete -size 512x512 tile:mpr:lines1 \
\) -composite \
\( \
-size 4x4 xc:white -alpha transparent \
-channel alpha -fx "(1-min(1,j%4)) * 0.25" \
-write mpr:lines2 +delete -size 512x512 tile:mpr:lines2 \
\) -composite \
wallpaper.png
which yields this. You may see that pattern is broken (especially at the bottom).
If I set pattern size to 64x64 the problem is gone but that's not a real fix.
What am I doing wrong and how do I fix that without changing the pattern size?
UPD:
Full magick --version (convert --version) output:
Version: ImageMagick 7.0.8-23 Q16 x86_64 2019-01-04 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenCL OpenMP
Delegates (built-in): bzlib cairo fontconfig freetype gslib heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps raw rsvg tiff webp wmf x xml zlib
Do the lines always appear at the same places from run to run
Yes, for each of the same set of arguments result is the same (but may vary for slightly different sets of arguments like changing resolution or removing write commands from braces).
Just as a test, try saving to TIFF rather than PNG. Does that works
or not?
Changing the output format always produces exactly the same result. I tried tiff, gif, jpeg. (With jpeg those lines are a bit blurred obviously, but result looks pretty much the same). This also applies to fmw42's command variant.
Do you have OpenMP installed with ImageMagick. Also disable OpenCL and see if that helps.
OpenMP is not installed but supported by the IM version I have.
Disabling OpenCL via environment variable MAGICK_OCL_DEVICE=OFF does not change the result. Recompiled IM with and without OpenCL and OpenMP from tag=7.0.8-23 and from master - all the same...
Are you seeing something in tmp4.png that is not visible to me?
Yes, I still can see that rainbow-colored line on white background if I do magick tmp4.png -alpha remove tmp4-opaque.png
Your command works fine for me on ImageMagick 7.0.8.23 Q16 Mac OSX with libpng 1.6.35. But in IM 7 use magick, not magick convert and not convert or you will get IM 6 behavior. Check your version of libpng and upgrade if necessary. What is your version and date of ImageMagick and on what platform?
magick \
\( \
-size 512x512 \
-define gradient:vector="0,0 0,720" gradient:"#5DA2C2-#C70AA0" +write tmp1.png \
\) \
\( \
-size 4x4 xc:white -alpha transparent +write tmp2.png \
-channel alpha -fx "(1-min(1,(j+1)%2)) * 0.1" +write tmp3.png \
-write mpr:lines1 +delete -size 512x512 tile:mpr:lines1 +write tmp4.png \
\) -composite \
\( \
-size 4x4 xc:white -alpha transparent \
-channel alpha -fx "(1-min(1,j%4)) * 0.25" \
-write mpr:lines2 +delete -size 512x512 tile:mpr:lines2 \
\) -composite \
wallpaper.png
Check this and see if it has your same issue. But I do not see any broken lines.
Related
I need to create a collage of 12 JPEG images using ImageMagick montage command:
montage image{1..12}.jpg -tile 3x4 -geometry +10+10 output.jpg
The command above creates a collage of 4 rows and 3 columns.
My aim is to add 3 labels (a), (b), (c) to the columns.
The result should look like:
(a) (b) (c)
img1 img2 img3
img4 img5 img6
img7 img8 img9
img10 img11 img12
I have tried using the -label flag but I can't get it to work.
My question is how can I add the labels as shown above?
I have the following version of ImageMagick:
Version: ImageMagick 7.1.0-13 Q16-HDRI x86_64 2021-10-29 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): bzlib fontconfig freetype jbig jng jp2 jpeg lcms lzma pangocairo png tiff webp x xml zip zlib
Compiler: gcc (8.4)
You can do that in Imagemagick by appending a label above the first 3 images and piping all images to montage. I use -smush to add space rather than -append.
convert \
\( -pointsize 32 label:"(a)" lena.jpg -gravity center -smush 20 -set label "" \) \
\( -pointsize 32 label:"(b)" mandril3.jpg -gravity center -smush 20 -set label "" \) \
\( -pointsize 32 label:"(c)" zelda1.jpg -gravity center -smush 20 -set label "" \) \
zelda1.jpg lena.jpg mandril3.jpg miff:- |\
montage - -tile 3x2 -geometry +10+10 result.jpg
I have the following script ImageMagick script
convert $tmpA4 \
\( -clone 0 -negate \) \
\( -size ${wd}x${ht} gradient: -negate \) \
-compose over -composite \
$tmpA4
Which I am trying to regenerate using Imagick but ended without any luck. Please find the code which I tried
$negate = clone($tmpA4);
$negate->negateImage(false);
file_put_contents("negateR.png",$negate);
$gradient = new Imagick();
$gradient->newPseudoImage(round($wd),round($ht), "gradient:white-black");
$gradient->setImageFormat("png");
$gradient->negateImage(false);
file_put_contents("gradientR.png",$gradient);
$negate->setImageAlphaChannel(imagick::ALPHACHANNEL_OPAQUE);
$negate->compositeimage($gradient, Imagick::COMPOSITE_COPYOPACITY , 0, 0);
$tmpA4->setImageCompose(imagick::COMPOSITE_OVER);
$tmpA4->compositeimage($negate, Imagick::COMPOSITE_OVER, 0, 0);
the negateR.png and gradientR.png are perfectly getting generated but the final composition doesn't.
Here is a simplified version of the code I'm currently using :
cat $FILES | while read line; do
convert -fill $FG_COLOR -background $BG_COLOR \
-size ${line_width}x${line_height} -page +${x_margin}+${y} \
label:"${varL} and ${varR}" miff:-
done | convert -size ${SCREEN_W}x${SCREEN_H} xc:$BG_COLOR - -flatten image.jpg
And it is working well !
But I wish to have different colors for ${varL} and ${varR}, and I guess I should use pango instead of label. Am I correct about that ?
But by keeping the same code and just replacing label by pango I have an unexpected error :
convert-im6.q16: width or height exceeds limit
I am very confused about how I was able to solve this.
Anyway here is the thing : I don't know why but pango needs to be BEFORE the other arguments.
convert -fill $FG_COLOR -background $BG_COLOR \
-size ${line_width}x${line_height} -page +${x_margin}+${y} \
pango:"${varL} and ${varR}" miff:-
Isn't working, but :
convert pango:"${varL} and ${varR}" \
-fill $FG_COLOR -background $BG_COLOR \
-size ${line_width}x${line_height} -page +${x_margin}+${y} miff:-
Is working !
EDIT: pango: need to be before -page
I am running ImageMagick on Mac OS High Sierra
The following commands work fine with ImageMagick 6.9.0
convert -define stream:buffer-size=0 png:- png:- -alpha off -compose copy-opacity -composite png:-
compare -define stream:buffer-size=0 -fuzz 17% -metric AE png:- png:- png:-
I updated ImageMagick 6.9.0 to ImageMagick 7.0.7-28 then both of these commands started failing with the below error messages
magick -define stream:buffer-size=0 png:- png:- -alpha off -compose copy-opacity -composite png:-
magick: improper image header `/var/folders/tb/11n2czg57ts9dzxypdsmlqk99c46m9/T/magick-26635byT1dtHsAuT3' # error/png.c/ReadPNGImage/4231.
magick compare -define stream:buffer-size=0 -fuzz 17% -metric AE png:- png:- png:-
For input string: "compare: improper image header `/var/folders/tb/11n2czg57ts9dzxypdsmlqk99c46m9/T/magick-26363xwcFdjrv3CT0' # error/png.c/ReadPNGImage/4231."
Can you please guide me what I have to change in those commands?
If I store png files in a temporary folder and run the above commands by replacing png:- with temporary file path then both the commands run fine. But I want the commands to work with InputStream.
Thanks in advance!
I'm not sure you can stream two PNG files concatenated together as PNGs into ImageMagick's input stream. Essentially, you are trying to do this:
{ convert xc:red png:- ; convert xc:blue png:- ; } | convert png:- png:- -append result.png
which doesn't work, because, I think, the final convert will read the entire input stream when it encounters the first png:- and there will be nothing left for the second png:-.
I think the only safe way to send multiple concatenated images through a single channel is by using the MIFF "Magic Image File Format" which does support multiple images:
{ convert xc:red miff:- ; convert xc:blue miff:- ; } | convert miff:- -append result.png
I use Imagemagick (www.imagemagick.org)
Since i am on hostgator i also have imagick and magickwand installed.
I can do simple manipulation with imagick and magickwand but if i want to reproduce the advanced tutorials at imagemagick.org i fail.
Goal:
make this working http://www.imagemagick.org/Usage/advanced/#jigsaw
Questions:
How can i do this with imagick or magickwand?
Could i somehow also communicate with the module imagemagick through command line, like exec(....)?
Thanks 4 short help
You can use exec() or shell_exec().
For example:
exec('/path/to/your/imagick/convert jigsaw_tmpl.png -edge .5 -blur 0x.5 jigsaw_edge.png');
One more reminder, exec() will not work in PHP safe mode.
Okay. The solution using the command-line commands straight is like the following:
exec("/usr/lib/convert user/set/seinfeld/image/image/data/apple_cinema_30.jpg -edge .5 -blur 0x.5 jaw_ege.png");
so obviously you have to know the path to the module and set the path to the images correctly (a).
will update if necessary with the instructions for imagick/magickwand.
I think it is to complicated to be run in Imagick - not saying it could not be - and as said above the best bet would be Imagemagick command line and exec( ). Build it up one command at a time; you may be able to combine commands later. Do not use jpg for any intermediate images as you will start to loose quality.
It depends what effect you are after as Anthony has a Bash script you could use linked towards the bottom of that section of the page.
You can run that with php using exec:
Upload the script to your server
CHMOD it to either 755 or 777 depending on your server setup
// Run the script
exec("/FULL PATH TO JIGSAW/jigsaw options input.jpg mask.png output.png 2>&1", $array);
//Display any errors
echo "<br>".print_r($array)."<br></pre>";
I do not know if this will work on a Hostgator account but I can not see why not.
Also I have not tried it and you need a mask image to go with your input image.
I have just tried this on my server and get an error: /bin/bash^M: bad interpreter: No such file or directory
This means nothing to me!
Making one jigsaw piece using Anthony's images and code with Imagemagick commaand line and exec( )
exec("convert jigsaw_tmpl.png -edge .5 -blur 0x.5 jigsaw_edge.png");
$cmd = " holocaust_md.jpg \( jigsaw_edge.png -negate \) -geometry +365+96 ".
" -compose multiply -composite -crop 100x100+365+96 +repage ";
exec("convert $cmd jigsaw_outline.png");
$cmd = " holocaust_md.jpg -crop 100x100+365+96! -background none -flatten ".
" +repage \( jigsaw_tmpl.png +matte \) -compose CopyOpacity -composite ".
" -rotate -20 -gravity center -crop 100x100+0+0 +repage ";
exec("convert $cmd jigsaw_cutout.png");
$cmd = " jigsaw_cutout.png \( +clone -channel A -separate +channel -negate ".
" -background black -virtual-pixel background -blur 0x2 -shade 120x21.78 ".
" -contrast-stretch 0% +sigmoidal-contrast 7x50% -fill grey50 -colorize 10% ".
" +clone +swap -compose overlay -composite \) -compose In -composite ";
exec("convert $cmd jigsaw_bevel.png");
$cmd = " jigsaw_bevel.png \( +clone -fill DarkSlateGrey -colorize 100% -repage +0+1 \) ".
" \( +clone -repage +1+2 \) \( +clone -repage +1+3 \) \( +clone -repage +2+4 \) ".
" \( +clone -repage +2+5 \) -background none -compose DstOver -flatten";
exec("convert $cmd jigsaw_thickness.png");
$cmd = " jigsaw_thickness.png \( +clone -background Black -shadow 50x3+4+4 \) ".
" -background none -compose DstOver -flatten";
exec("convert $cmd jigsaw_shadow.png");