Gradient Caption Magick.NET #781
Replies: 6 comments 6 replies
-
What have you tried so far? At what point are you stuck? |
Beta Was this translation helpful? Give feedback.
-
What we have tried:
Where we are stuck:
convert -size 374x550 -background none -font "PathToFontFile" -gravity center caption:"Nations Cup" ( -clone 0 -alpha opaque -sparse-color Barycentric "0, 0 #070504 %[fx:w-1],0 #000000" ) ( -clone 0 -alpha transparent ) -reverse -compose dstover -composite "PathToLocation" convert -size 374x550 -background none -font "PathToFontFile" -gravity center caption:"Nations Cup" ( -clone 0 -alpha opaque -sparse-color Barycentric "0, 0 #070504 0,%[fx:h-1], #000000" ) ( -clone 0 -alpha transparent ) -reverse -compose dstover -composite "PathToLocation" convert -size 374x550 -background none -font "PathToFontFile" -gravity center caption:"Nations Cup" ( +clone -sparse-color Barycentric "0, %h #070504 %w,0 #000000" ) -compose In -composite -virtual-pixel transparent -distort arc 80 ( +clone -background none -shadow 100x2+4+4 ) +swap -background none -compose over -layers merge +repage "PathToLocation"
|
Beta Was this translation helpful? Give feedback.
-
The example command that you have does not create the sample image that you provided? Here is a translation of your first command:
var readSettings = new MagickReadSettings
{
// -size 374x550
Width = 374,
Height = 550,
// -background none
BackgroundColor = MagickColors.None,
// -font "PathToFontFile"
Font = "PathToFontFile",
// -gravity center
TextGravity = Gravity.Center,
};
// caption:"Nations Cup"
using (var image = new MagickImage("caption:Nations Cup", readSettings))
{
// -clone 0
using (var clone1 = image.Clone())
{
// -alpha opaque
clone1.Alpha(AlphaOption.Opaque);
// -sparse-color Barycentric "0, 0 #070504 %[fx:w-1],0 #000000"
var sparseColorArgs = new[]
{
// 0, 0 #070504
new SparseColorArg(0, 0, new MagickColor("#070504")),
// %[fx:w-1],0 #000000
new SparseColorArg(image.Width - 1, 0, new MagickColor("#000000")),
};
// -sparse-color Barycentric
clone1.SparseColor(SparseColorMethod.Barycentric, sparseColorArgs);
// -clone 0
using (var clone2 = image.Clone())
{
// -alpha transparent
clone2.Alpha(AlphaOption.Transparent);
// -reverse changes the order of the images. The order was:
// image, clone1, clone2 but this is not clone2, clone1, image.
// -compose dstover -composite
// Because there are there images some special magick is happening.
using (var clone3 = clone2.Clone())
{
clone2.Composite(clone1, CompositeOperator.DstOver);
clone2.Composite(image, CompositeOperator.CopyAlpha);
clone3.Composite(clone2, CompositeOperator.Over);
// "PathToLocation"
clone3.Write("PathToLocation");
}
}
}
} Feel free to ask if you have any further questions. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the help, the above code worked perfectly for both horizontal and vertical gradient effects.
We need help with overlaying the caption in an arc where we pass the angle of arc as parameter to the IM command. Below is the command for it convert -size 374x550 -background none -font "PathToFontFile" -gravity center caption:"Nations Cup" ( +clone -sparse-color Barycentric "0, %h #070504 %w,0 #000000" ) -compose In -composite -virtual-pixel transparent -distort arc 80 ( +clone -background none -shadow 100x2+4+4 ) +swap -background none -compose over -layers merge +repage "PathToLocation" Can you please help us in translating this command to Magick.NET code? |
Beta Was this translation helpful? Give feedback.
-
What have you tried yourself and where are you stuck? |
Beta Was this translation helpful? Give feedback.
-
Your commands could be translated to this: var settings = new MagickReadSettings
{
BackgroundColor = MagickColors.None, // -background none
FillColor = new MagickColor("#f9f9fa"), // -fill #f9f9fa
Font = "LeagueGothic-Regular.otf", // -font "LeagueGothic-Regular.otf"
Width = 1536,
Height = 864, // -size 1536x864
TextGravity = Gravity.Center, // -gravity center
};
using (var caption = new MagickImage("caption:Bledisloe Cup", settings))
{
using (var sparseColorImage = caption.Clone()) // +clone
{
var sparseColorArgs = new SparseColorArg[2];
sparseColorArgs[0] = new SparseColorArg(0, caption.Height, new MagickColor("#f9f9fa")); // 0, %h #f9f9fa
sparseColorArgs[1] = new SparseColorArg(caption.Width, 0, new MagickColor("#cdff37")); // %w,0 #cdff37
sparseColorImage.SparseColor(SparseColorMethod.Barycentric, sparseColorArgs); // -sparse - color Barycentric
caption.Composite(sparseColorImage, CompositeOperator.In); // -compose In -composite
}
caption.VirtualPixelMethod = VirtualPixelMethod.Transparent; // -virtual-pixel
caption.Distort(DistortMethod.Arc, 50); // -distort arc 50
using (var overlay = caption.Clone()) // +clone
{
// not sure why this needs to be black instead of none.
overlay.BackgroundColor = MagickColors.Black;
overlay.Shadow(4, 4, 2, new Percentage(100)); // -shadow 100x2+4+4
// Easier than -compose over -layers merge
overlay.Composite(caption, CompositeOperator.Over);
using (var background = new MagickImage("background.jpg"))
{
// composite -gravity center
background.Composite(overlay, Gravity.Center, CompositeOperator.Over);
background.Write("a.jpg");
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am working on a C# project which currently invokes IM commands for creating images with titles. I'm now switching over to using Magick.NET.
Having trouble converting the following command to Magick.NET -
convert -size 374x550 -background none -font "PathToFontFile" -gravity center caption:"Title" ( -clone 0 -alpha opaque -sparse-color Barycentric "0, 0 #070504 %[fx:w-1],0 #000000" ) ( -clone 0 -alpha transparent ) -reverse -compose dstover -composite "PathToLocation"
I'd really appreciate any help as I have been stuck on this for weeks now.
Thanks
Nihaar Nandedkar
(Note: Below is an example of what I am trying to achieve)

Beta Was this translation helpful? Give feedback.
All reactions