# I cropped a jpg but need help to fix the scale

**URL:** https://forum.kirupa.com/t/i-cropped-a-jpg-but-need-help-to-fix-the-scale/59881
**Category:** flash
**Created:** [August 4, 2004, 3:38pm UTC](https://forum.kirupa.com/t/i-cropped-a-jpg-but-need-help-to-fix-the-scale/59881 "2004-08-04T15:38:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kensapp](https://avatars.discourse-cdn.com/v4/letter/k/3da27b/32.png) [@kensapp](https://forum.kirupa.com/u/kensapp)
#### Post date: [August 4, 2004, 3:38pm UTC](https://forum.kirupa.com/t/i-cropped-a-jpg-but-need-help-to-fix-the-scale/59881/1 "2004-08-04T15:38:28Z")

</div>

**cropping a jpg image**  
I have created the following code below.

I want to load an external image. And break it into a specified number of rows and columns. I have successfully cropped it and assigned it to a movie clip that has actions attached, but I want to be able to split it into various numbers of columns and rows based on variables.

To do this I had to scale the “peice” to the correct size.

It currently works at generating the necessary size of each piece and placing the image where I want it when no scaling is needed. (300x300 image with a 100 x 100 cell) Yet when I scale the image, the jpg also gets scaled and distorted.

Trace statements show all positioning calculations to be correct. i have the offsets in x,y coordinates of the portion of the larger image i want and it does that correctly as well.

But how do I correct the scaling problem for the image that is inside the MC “piece”? While i want to MC container to scale, I want to leave the clipped image inside at 100% and not be scaled.

I was thinking I could somehow enlarge the inside image so that it offsets the reduction of the container, but not sure how to do that…

Any help would be greatly appreciated… I want to do this to create a variety of different puzzles…including a sliding puzzle.

an online version of the swf is here… so you can see what is happening…  
[http://www.vanishingcookies.com/fla…/testloader.swf](http://www.vanishingcookies.com/flashfiles/testloader.swf)

you can download the source files here  
[http://www.vanishingcookies.com/fla…/testloader.zip](http://www.vanishingcookies.com/flashfiles/testloader.zip)

Here is the source code in question…

id = 0;  
puz=“puz1.jpg”;//source image  
imagewidth=300;//width of source image  
imageheight=300;//height of source image  
rows=4; //number of rows – this will change  
cols=4; //number of columns – this will change  
xsize=imagewidth/cols; //calculate the size of each peice  
ysize=imagewidth/rows;  
map = new Array();  
map[0] = [];  
map[1] = [];  
map[2] = [];  
xstart = 20; //start coordinates of grid  
ystart = 20;  
pieceArray = [0];  
//pieceArray[1]=id+1=\_root.piece1;  
scalex=imagewidth/100/cols; //calculate necessary scaling of target clip  
trace (scalex);  
scaley=imageheight/100/rows;  
trace (scaley);

//Create and position pieces  
for (var row = 0; row\<rows; row++) {  
for (var col = 0; col\<cols; col++) {  
id++; // peice number  
attachMovie(“piece”, “piece”+id, id);  
var clip = \_root[“piece”+id];  
// --------  
trace (clip);  
clip.id = id;  
clip.row = row;  
clip.col = col;  
clip.orgRow = row;  
clip.orgCol = col;  
clip.numHint.txt = clip;  
pieceArray.push(clip);  
map[col][row] = clip;  
clip.\_x = xsize_col+xstart;  
clip.\_xscale = xsize;  
clip.\_yscale = ysize;  
clip.\_y = ysize_row+ystart;  
loadMovie (“puz1.jpg”, “piece”+id+".loader");  
picholder=“piece”+id+".loader"  
xoffset=(-xsize_col);  
yoffset=(-ysize_row);  
trace (xoffset);  
trace (yoffset);  
setProperty (picholder, \_x, xoffset);  
setProperty (picholder, \_y, yoffset);  
}  
}

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 4, 2004, 4:12pm UTC](https://forum.kirupa.com/t/i-cropped-a-jpg-but-need-help-to-fix-the-scale/59881/2 "2004-08-04T16:12:42Z")

</div>

here is the corrected code if it helps someone else… basic presumption was right… I just scale the jpg image it to the inverse of the previous scaling to the holder

id = 0;  
puz="puz1.jpg"  
imagewidth=300;  
imageheight=300;  
rows=10;  
cols=10;  
xsize=imagewidth/cols;  
ysize=imagewidth/rows;  
map = new Array();  
xstart = 20;  
ystart = 20;  
pieceArray = [0];  
//pieceArray[1]=id+1=\_root.piece1;

for (var row = 0; row\<rows; row++) {  
for (var col = 0; col\<cols; col++) {  
id++;  
attachMovie(“piece”, “piece”+id, id);  
var clip = \_root[“piece”+id];  
// --------  
trace (clip);  
clip.id = id;  
clip.row = row;  
clip.col = col;  
clip.orgRow = row;  
clip.orgCol = col;  
clip.numHint.txt = clip;  
pieceArray.push(clip);  
map[col][row] = clip;  
clip.\_x = xsize_col+xstart;  
clip.\_xscale = 3/cols_100;  
clip.\_yscale = 3/rows_100;  
clip.\_y = ysize_row+ystart;  
loadMovie (“puz1.jpg”, “piece”+id+".loader");  
picholder=“piece”+id+".loader"  
xoffset=(-xsize_col_cols/3);  
yoffset=(-ysize_row_rows/3);  
trace (xoffset);  
trace (yoffset);  
setProperty (picholder, \_x, xoffset);  
setProperty (picholder, \_y, yoffset);  
setProperty (picholder, \_xscale, cols/3_100);  
setProperty (picholder, \_yscale, rows/3_100);

```
 }

```

}
