Skip to content

Commit f58cc1c

Browse files
Merge pull request #709 from sketch-hq/refactor-original-size-method
Remove resizeToOriginalSize method
2 parents 4b3461a + 4656039 commit f58cc1c

File tree

4 files changed

+6
-40
lines changed

4 files changed

+6
-40
lines changed

CHANGELOG.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"unreleased": [
3-
"[New] Add `resizeToOriginalSize` method on `Image`",
43
"[New] Add `size` property on `ImageData`"
54
],
65
"releases": {

Source/dom/layers/Image.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ export class Image extends StyledLayer {
2626

2727
super(layer)
2828
}
29-
30-
resizeToOriginalSize() {
31-
if (this.isImmutable()) {
32-
return this
33-
}
34-
this._object.resizeToOriginalSize()
35-
return this
36-
}
3729
}
3830

3931
Image.type = Types.Image
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* globals expect, test */
2-
import { canBeLogged, base64Image } from '../../../test-utils'
2+
import { canBeLogged } from '../../../test-utils'
33
import { Image } from '../..'
44

55
test('should create an empty image', (context, document) => {
@@ -12,22 +12,3 @@ test('should create an empty image', (context, document) => {
1212
expect(image.image).toBe(null)
1313
canBeLogged(image, Image)
1414
})
15-
16-
test('should resize image to its original size', (context, document) => {
17-
const page = document.selectedPage
18-
19-
const image = new Image({
20-
image: {
21-
base64: base64Image,
22-
},
23-
parent: page,
24-
})
25-
26-
expect(image.frame.width).toBe(100)
27-
expect(image.frame.height).toBe(100)
28-
29-
image.resizeToOriginalSize()
30-
31-
expect(image.frame.width).toBe(50)
32-
expect(image.frame.height).toBe(50)
33-
})

docs/api/Image.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,13 @@ var imageLayer = new Image({
5858

5959
By default, an `Image` layer will be created with a size of 100 × 100 pixels, unless you provide a `frame` property on its constructor.
6060

61-
## Original Size
62-
63-
```js
64-
imageLayer.resizeToOriginalSize()
61+
```javascript
62+
const image = imageLayer.image
63+
imageLayer.frame.width = image.size.width
64+
imageLayer.frame.height = image.size.height
6565
```
6666

67-
Adjust the Image to its original size. This is equivalent to pressing the 'Original Size' button in Sketch's Inspector.
68-
69-
### Returns
70-
71-
The current Image (useful if you want to chain the calls).
72-
73-
For performance reasons, Sketch initializes the `Image` object lazily. So if you want to set the dimensions of your Image layer to those of the original file, you'll first need to create the object, and then call the `resizeToOriginalSize` method.
67+
For performance reasons, Sketch initializes the `Image` object lazily. So if you want to set the dimensions of your Image layer to those of the original file, you'll first need to create the object, and then set its frame dimensions.
7468

7569
## `ImageData`
7670

0 commit comments

Comments
 (0)