             guard let weakself = self else {
                 return
             }
-
-            let realImageSize = weakself.getRealImageSize(weakself.image)
+            guard let image = weakself.image else{
+                return
+            }
+            let realImageSize = weakself.getRealImageSize(image)
             // Create a containerView to hold the image should apply gaussian blur.
             let containerView = UIView(frame: CGRect(origin: .zero, size: realImageSize.scaled(by: 1.4)))
             containerView.backgroundColor = .clear
             let blurImageView = UIImageView(frame: CGRect(origin: .zero, size: realImageSize))
             blurImageView.center = containerView.center
-            blurImageView.image = weakself.image
+            blurImageView.image = image
             blurImageView.layer.cornerRadius = weakself.imageCornerRaidus
             blurImageView.layer.masksToBounds = true
             containerView.addSubview(blurImageView)
-
+            
+            var containerImage = UIImage()
             // Get the UIImage from a UIView.
-            let containerImage = UIImage(view: containerView)
+            if containerView.frame.size != CGSize.zero {
+                containerImage = UIImage(view: containerView)
+            }else {
+                containerImage = UIImage()
+            }
 
             guard let resizedContainerImage = containerImage.resized(withPercentage: 0.2),
                 let ciimage = CIImage(image: resizedContainerImage),

    private func layoutShadow() {

        generateBlurBackground()

        let realImageSize = getRealImageSize(image)


        didSet {
            blurredImageView.alpha = shadowAlpha
        }
    }
    
    override var contentMode: UIViewContentMode {
        didSet{
            layoutShadow()
        }
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        layoutShadow()
    }

    /// Generate the background color and set it to a image view.
