title: CAlayer to UIImage bug with shadow
body: <p>i'm trying to render UIImage from CALayer keeping shadows, but the resulting image is different from the image in CALayer, why?</p>
  <p>code</p>
  <pre><code>override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view.
          
          self.view.backgroundColor = UIColor.black
          
          
          let containerLayer = CALayer()
          containerLayer.frame = CGRect(x: 100, y: 20, width: 40, height: 200)
          
          let layerGradient = CAGradientLayer()
          layerGradient.frame = CGRect(x: 15, y: 0, width: 10, height: 200)
          layerGradient.startPoint = CGPoint(x: 0, y: 0.5)
          layerGradient.endPoint = CGPoint(x: 1, y: 0.5)
          layerGradient.colors = [UIColor.black.cgColor, UIColor.white.cgColor, UIColor.black.cgColor]
          layerGradient.shadowOffset = CGSize(width: -3, height: 0)
          layerGradient.shadowPath = UIBezierPath(rect: CGRect(x: 0, y: 0, width: 15, height: 200)).cgPath
          layerGradient.shadowRadius = 7
          layerGradient.shadowColor = UIColor.black.cgColor
          layerGradient.shadowOpacity = 1
          
          containerLayer.backgroundColor = UIColor.white.cgColor
          
          containerLayer.addSublayer(layerGradient)
          self.view.layer.addSublayer(containerLayer)
          
          
          let imageSeparator = imageFromLayer(layer: containerLayer)
                 
          let img = UIImageView(image: imageSeparator)
          self.view.addSubview(img)
          
      }
  
      func imageFromLayer(layer:CALayer) -&gt; UIImage {
          UIGraphicsBeginImageContextWithOptions(layer.frame.size, layer.isOpaque, layer.contentsScale)
          layer.render(in: UIGraphicsGetCurrentContext()!)
          let outputImage = UIGraphicsGetImageFromCurrentImageContext()
          UIGraphicsEndImageContext()
          return outputImage!
      }
  </code></pre>
  <p>CALayer</p>
  <p><a href="https://i.stack.imgur.com/DbSR3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DbSR3.png" alt="enter image description here" /></a></p>
  <p>Result UIImage</p>
  <p><a href="https://i.stack.imgur.com/jsTyN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jsTyN.png" alt="enter image description here" /></a></p>
  <p>where am i wrong?</p>