title: Apply gradient mask on image that already has transparency with ImageMagick?
body: <p>I've got a PNG image with transparency:</p>
  
  <p><a href="https://i.imgur.com/YkjVXkE.png" rel="noreferrer">original.png</a><br>
  <img src="https://i.imgur.com/YkjVXkE.png" alt="Original"></p>
  
  <p>Now I want to use ImageMagick to <strong>apply a diagonal gradient to its alpha channel</strong>. I mean so that its opacity remains in the top left corner, and gradually fades out to completely transparent in the bottom right corner. Like this:</p>
  
  <p><a href="https://i.imgur.com/hH52SuU.png" rel="noreferrer">result.png</a><br>
  <img src="https://i.imgur.com/hH52SuU.png" alt="Result"></p>
  
  <p>So basically I want to generate a gradient, and use that as a mask for the image. But the image already has an alpha channel (transparency) of its own. Here's a visualisation of what I'm trying:</p>
  
  <p><img src="https://i.imgur.com/IUuax1R.png" alt="Operation"></p>
  
  <p>(original and result here displayed on checkerboard for visiblity, but I mean actual transparency)</p>
  
  <p>I think I understand how to generate a diagonal gradient (the <a href="http://www.imagemagick.org/Usage/canvas/#diagonal_gradients" rel="noreferrer">barycentric gradient</a> command is very useful for this). But this creates a gradient in the <strong>color channels</strong> i.e. a colored or grayscale gradient. Whereas I want to apply the gradient on the <strong>alpha</strong> channel.</p>
  
  <p>From the <a href="http://www.imagemagick.org/Usage/compose/#copyopacity" rel="noreferrer">IM manual</a> I understand the <code>-compose CopyOpacity</code> operator could be used for this. However this seems to <em>copy</em> the alpha from the mask on to my image. I need to "apply" this gradient color on my existing alpha channel, so basically I need my image's alpha channel to be <em>multiplied</em> by the grayscale color from the gradient image.</p>
  
  <p>What would be the correct IM command line to perform the operation displayed above?</p>