ImageMagick creating blank transparent square(s) according to width
Posted: 2018-03-23T23:27:21-07:00
Hey all I am trying to fill in the area with blank circles but its turning out looking like this:
(sized down in order not to take up so much room here. Original size: 360x1200). Also note that I do not really use the blank.png file - its just there so i can check to see if its being used or not. I'm making just a plain color box as the "blank.png".
My code:
In the above code, I am creating a white 100x100 square. Then im resizing that to 100x100 and turning the white background transparent for the blank image.
The error I get is:
on the result.Write(@"C:\Users\David\Pictures\final.png"); line.
When I have just this code running:
It seems to work just fine...
How can I make this work as I am needing it too?
Images used:
---------------------------------------------
---------------------------------------------
Blank.png start ----
Blank.png end ----
What I am wanting it to look like:
Which really looks like this since blank.png is transparent:
The width will be different depending on how many blank.png images are needed to be inserted to get that width. The example above has 5 images of which 4 are the blank ones.
(sized down in order not to take up so much room here. Original size: 360x1200). Also note that I do not really use the blank.png file - its just there so i can check to see if its being used or not. I'm making just a plain color box as the "blank.png".
My code:
Code: Select all
using (MagickImageCollection images = new MagickImageCollection())
{
List<string> lFiles = new List<string>();
lFiles.Add(@"C:\Users\David\Pictures\1.jpg");
lFiles.Add(@"C:\Users\David\Pictures\blank.png");
lFiles.Add(@"C:\Users\David\Pictures\blank.png");
lFiles.Add(@"C:\Users\David\Pictures\blank.png");
lFiles.Add(@"C:\Users\David\Pictures\blank.png");
IMagickImage roundImg = new MagickImage();
IMagickImage mask = new MagickImage();
IMagickImage shadow = new MagickImage();
IMagickImage result = new MagickImage();
bool isBlankImage = false;
foreach (string tempFBProfileImg in lFiles)
{
roundImg = new MagickImage(tempFBProfileImg);
if (Regex.IsMatch(@"C:\Users\David\Pictures\blank.png", @"\bblank.png\b"))
{
roundImg = new MagickImage(MagickColors.White, 100, 100);
roundImg.Resize(100, 100);
roundImg.Transparent(MagickColors.White);
}
else
{
mask = new MagickImage("xc:black", 100, 100);
mask.Settings.FillColor = MagickColors.White;
mask.Draw(new DrawableCircle(50, 50, 50, 90));
mask.HasAlpha = false;
roundImg.Resize(100, 100);
roundImg.Composite(mask, CompositeOperator.CopyAlpha);
roundImg.Draw(
new DrawableStrokeColor(MagickColors.Black),
new DrawableStrokeWidth(1),
new DrawableFillColor(MagickColors.None),
new DrawableCircle(50, 50, 50, 90)
);
shadow = new MagickImage("xc:none", 100, 100);
shadow.Settings.FillColor = MagickColors.Black;
shadow.Draw(new DrawableCircle(50, 50, 50, 90));
shadow.Blur(0, 5);
roundImg.Composite(shadow, CompositeOperator.DstOver);
}
images.Add(roundImg);
images.First().BackgroundColor = MagickColors.None;
result = images.SmushHorizontal(-35);
result.Resize(360, 0);
result.Write(@"C:\Users\David\Pictures\final.png");
}
}
The error I get is:
'width or height exceeds limit `#FFFFFFFFFFFF' @ error/cache.c/OpenPixelCache/3491'
on the result.Write(@"C:\Users\David\Pictures\final.png"); line.
When I have just this code running:
Code: Select all
MagickImage roundImg = new MagickImage(MagickColors.White, 100, 100);
roundImg.Resize(100, 100);
roundImg.Transparent(MagickColors.White);
roundImg.Write(@"C:\Users\David\Pictures\aloneTest.png");
How can I make this work as I am needing it too?
Images used:
---------------------------------------------
---------------------------------------------
Blank.png start ----
Blank.png end ----
What I am wanting it to look like:
Which really looks like this since blank.png is transparent:
The width will be different depending on how many blank.png images are needed to be inserted to get that width. The example above has 5 images of which 4 are the blank ones.