diff --git a/src/scale/mod.rs b/src/scale/mod.rs
index 07eab49..58e9b86 100644
--- a/src/scale/mod.rs
+++ b/src/scale/mod.rs
@@ -894,6 +894,32 @@ impl<'a> Render<'a> {
                         let mut base_w = 0u32;
                         let mut base_h = 0u32;
                         let mut ok = true;
+
+                        let mut total_bounds = zeno::Bounds::empty();
+
+                        for i in 0..outline.len() {
+                            let layer = match outline.get(i) {
+                                Some(layer) => layer,
+                                _ => {
+                                    ok = false;
+                                    break;
+                                }
+                            };
+                            let bounds = layer.bounds();
+                            total_bounds = total_bounds.grow(&bounds);
+                        }
+
+                        base_x = total_bounds.min.x as i32;
+                        base_y = total_bounds.min.y as i32;
+                        base_w = total_bounds.width() as u32;
+                        base_h = total_bounds.height() as u32;
+
+                        image.data.resize((base_w * base_h * 4) as usize, 0);
+                        image.placement.left = 0;
+                        image.placement.top = 0;
+                        image.placement.width = total_bounds.width() as u32;
+                        image.placement.height = total_bounds.height() as u32;
+
                         for i in 0..outline.len() {
                             let layer = match outline.get(i) {
                                 Some(layer) => layer,
@@ -902,6 +928,7 @@ impl<'a> Render<'a> {
                                     break;
                                 }
                             };
+                            
                             scratch.clear();
                             let placement = Mask::with_scratch(layer.path(), rcx)
                                 .origin(Origin::BottomLeft)
@@ -911,14 +938,6 @@ impl<'a> Render<'a> {
                                     scratch.resize(fmt.buffer_size(w, h), 0);
                                 })
                                 .render_into(&mut scratch[..], None);
-                            if i == 0 {
-                                base_x = placement.left;
-                                base_y = placement.top;
-                                base_w = placement.width;
-                                base_h = placement.height;
-                                image.data.resize((base_w * base_h * 4) as usize, 0);
-                                image.placement = placement;
-                            }
                             let color = layer
                                 .color_index()
                                 .map(|i| palette.map(|p| p.get(i)))
@@ -929,7 +948,7 @@ impl<'a> Render<'a> {
                                 placement.width,
                                 placement.height,
                                 placement.left.wrapping_sub(base_x),
-                                base_y.wrapping_sub(placement.top),
+                                (base_h as i32 + base_y).wrapping_sub(placement.top),
                                 color,
                                 &mut image.data,
                                 base_w,