Skip to content

Commit 0b12891

Browse files
author
Irene Alvarado
committed
Add image manipulation library
1 parent 79dee10 commit 0b12891

File tree

13 files changed

+73
-18
lines changed

13 files changed

+73
-18
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ console.log(newfile)
2424

2525
Can be found in the examples folder:
2626

27-
* `deno run --allow-read --allow-write examples/csv-example.ts`
28-
* `deno run --allow-read --allow-write examples/arquero-example.ts`
27+
* `deno run --allow-read --allow-write examples/csv/csv-example.ts`
28+
* `deno run --allow-read --allow-write examples/csv/arquero-example.ts`
29+
* `deno run -A examples/image/image-example.ts`
2930

3031
## Testing
3132

3233
Run all the tests:
3334

34-
`deno test --allow-read --allow-write tests/*`
35+
`deno test -A tests/*`
3536

3637
Run separate tests
3738

38-
`deno test --allow-read --allow-write tests/csv-test.ts`
39+
`deno test -A tests/csv-test.ts`
3940

4041

4142
## License

examples/csv/arquero-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ t = t
2222
// Sort rows by duration, descreasing
2323
.orderby(aq.desc("duration"));
2424

25-
await Deno.writeTextFile("./examples/flights2.csv", t.toCSV());
25+
await Deno.writeTextFile("./examples/csv/flights2.csv", t.toCSV());

examples/flights2.csv

Lines changed: 0 additions & 10 deletions
This file was deleted.
147 KB
Loading

examples/image/cat-cropped.jpeg

176 KB
Loading

examples/image/cat-gif.gif

167 KB
Loading

examples/image/cat-resized.jpeg

162 KB
Loading

examples/image/cat.jpeg

74.7 KB
Loading

examples/image/image-example.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { loadImage, loadImageBytes } from '../../image.ts'
2+
import { Image } from 'https://cdn.deno.land/imagescript/versions/1.2.0/raw/mod.ts'; // library for image manipulations
3+
4+
const url = 'https://api.creativecommons.engineering/v1/thumbs/c8fe5f5b-cc1a-4794-91c5-7488c60f4914'
5+
const url2 = 'https://live.staticflickr.com/962/41906373431_72c25d0dfd_b.jpg'
6+
const url3 = 'https://i.giphy.com/media/5wWf7HapUvpOumiXZRK/giphy.gif'
7+
8+
// Can specify a filename to rename the image
9+
// (image url, path to save image, image to save name)
10+
loadImage(url, './examples/image/', 'cat')
11+
12+
// Image will be saved with the default name if not included
13+
loadImage(url2, './examples/image/')
14+
15+
// Can load gifs, pngs, jpgs
16+
loadImage(url3, './examples/image/', 'cat-gif')
17+
18+
// Image manipulation example - reading from a file
19+
const bytes = await Deno.readFile('./examples/image/cat.jpeg') // local file
20+
const image = await Image.decode(bytes);
21+
image.crop(image.width/4, image.height/4, image.width/2, image.height/2); // x, y, width, height
22+
await Deno.writeFile('./examples/image/cat-cropped.jpeg', await image.encode());
23+
24+
// Image manipulation example - fetching from a url
25+
const { imageBytes, mimeType } = await loadImageBytes(url) // url
26+
const image2 = await Image.decode(imageBytes);
27+
image2.resize(image2.width/2, image2.height/2)
28+
image2.opacity(0.5).invert()
29+
await Deno.writeFile('./examples/image/cat-resized.jpeg', await image2.encode());

examples/write-example.csv

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)