         
         var queryItems = components.queryItems ?? [URLQueryItem]()
         
-        let width = min(rect.width * block.backgroundScale, backgroundImage.size.width)
-        let height = min(rect.height * block.backgroundScale, backgroundImage.size.height)
-        let x = (backgroundImage.size.width - width) / 2
-        let y = (backgroundImage.size.height - height) / 2
-        
-        func floatParam(_ float: CGFloat) -> String {
+        let floatToString = { (float: CGFloat) -> String in
             let r = float.rounded()
             let i = Int(r)
             return i.description
         }
         
-        let value = [
-            floatParam(x),
-            floatParam(y),
-            floatParam(width),
-            floatParam(height)
-        ].joined(separator: ",")
-        
-        let rect = URLQueryItem(name: "rect", value: value)
-        queryItems.append(rect)
-        
-        var deviceScale = block.backgroundScale
+        let value = [rect.origin.x, rect.origin.y, rect.size.width, rect.size.height].map(floatToString).joined(separator: ",")
+        queryItems.append(URLQueryItem(name: "rect", value: value))
+        
+        var scale = block.backgroundScale
         
         if UIScreen.main.scale < block.backgroundScale {
-            let scaledWidth = floatParam(width / block.backgroundScale * UIScreen.main.scale)
+            let scaledWidth = floatToString(rect.size.width / block.backgroundScale * UIScreen.main.scale)
             let w = URLQueryItem(name: "w", value: scaledWidth)
             queryItems.append(w)
             
-            let scaledHeight = floatParam(height / block.backgroundScale * UIScreen.main.scale)
+            let scaledHeight = floatToString(rect.size.height / block.backgroundScale * UIScreen.main.scale)
             let h = URLQueryItem(name: "h", value: scaledHeight)
             queryItems.append(h)
             
-            deviceScale = UIScreen.main.scale
+            scale = UIScreen.main.scale
         }
         
         components.queryItems = queryItems

        return components.url
    }
    
    func backgroundView(forBlock block: Block?, inRect rect: CGRect) -> UIImageView? {
        guard let block = block, let backgroundImage = block.backgroundImage else {
            return nil
        }
        
        switch block.backgroundContentMode {
        case .Original:
            return croppedBackgroundView(forBlock: block, backgroundImage: backgroundImage, inRect: rect)
        default:
            return nil
        }
    }

    func croppedBackgroundView(forBlock block: Block, backgroundImage: Image, inRect rect: CGRect) -> UIImageView? {
        guard var components = URLComponents(url: backgroundImage.url, resolvingAgainstBaseURL: false) else {
            return nil


extension UIImageView {
    func setBackgroundImage(url: URL, contentMode: ImageContentMode, scale: CGFloat) {
        AssetManager.sharedManager.fetchAsset(url: url) { data in
            guard let data = data, let image = UIImage(data: data, scale: scale) else {
                return
            }
            
            switch contentMode {
            case .Tile:
                self.backgroundColor = UIColor(patternImage: image)
