title: ImageMagick creating blank transparent square(s) according to width
body: <p>Hey all I am trying to fill in the area with blank circles, but its turning out looking like this:</p>
  
  <p>(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".</p>
  
  <p><a href="https://i.stack.imgur.com/mwFzF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mwFzF.png" alt="enter image description here"></a></p>
  
  <p>My code:</p>
  
  <pre><code>using (MagickImageCollection images = new MagickImageCollection())
          {
              List&lt;string&gt; lFiles = new List&lt;string&gt;();
  
              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");
              }
          }
  </code></pre>
  
  <p>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.</p>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p>'width or height exceeds limit `#FFFFFFFFFFFF' @ error/cache.c/OpenPixelCache/3491'</p>
  </blockquote>
  
  <p>on the result.Write(@"C:\Users\David\Pictures\final.png"); line.</p>
  
  <p>When I have just this code running:</p>
  
  <pre><code>MagickImage roundImg = new MagickImage(MagickColors.White, 100, 100);
  roundImg.Resize(100, 100);
  roundImg.Transparent(MagickColors.White);
  roundImg.Write(@"C:\Users\David\Pictures\aloneTest.png");
  </code></pre>
  
  <p>It seems to work just fine...</p>
  
  <p><a href="https://i.stack.imgur.com/2LRv1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2LRv1.png" alt="enter image description here"></a></p>
  
  <p>How can I make this work as I am needing it too?</p>
  
  <p>Images used:</p>
  
  <hr>
  
  <p><a href="https://i.stack.imgur.com/ZME5U.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZME5U.jpg" alt="enter image description here"></a></p>
  
  <hr>
  
  <p>Blank.png start ----</p>
  
  <p><a href="https://i.stack.imgur.com/Vkq2a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Vkq2a.png" alt="enter image description here"></a> </p>
  
  <p>Blank.png end ----</p>
  
  <p>What I am wanting it to look like is this:</p>
  
  <p><a href="https://i.stack.imgur.com/4Tax9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Tax9.png" alt="enter image description here"></a></p>
  
  <p>which really looks like this, since blank.png is transparent:</p>
  
  <p><a href="https://i.stack.imgur.com/wXP0Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wXP0Q.png" alt="enter image description here"></a></p>
  
  <p>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.</p>
  
  <p>Using Bonzos example in C#:</p>
  
  <pre><code> roundImg.Resize(new MagickGeometry(100, 100));
   roundImg.BackgroundColor = MagickColors.Transparent;
   roundImg.Extent(360, 100, Gravity.West);
   result = roundImg;
  </code></pre>
  
  <p>Produces just a transparent 360x100 image.</p>
  
  <p>Tried fmw42:</p>
  
  <pre><code> mask = new MagickImage("xc:black", 100, 100);
   mask.Settings.FillColor = MagickColors.White;
   mask.Draw(new DrawableCircle(50, 50, 50, 100));
   mask.HasAlpha = false;
   mask.Resize(100, 100);
   roundImg.Composite(mask, CompositeOperator.CopyAlpha);
  </code></pre>
  
  <p><strong>Possible solution</strong></p>
  
  <pre><code> if (Regex.IsMatch(tempFBProfileImg.ToLower(), @"\bblank.png\b"))
   {
      result.Extent(360, 100, Gravity.West);
      images.Add(result);
      break;
   }
  </code></pre>
  
  <p>which results in:</p>
  
  <p><a href="https://i.stack.imgur.com/2CzBo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2CzBo.png" alt="enter image description here"></a></p>