Skip to content

Commit 6a7dcc3

Browse files
author
Irene Alvarado
committed
Remove name parameter for image library
1 parent 52b59a6 commit 6a7dcc3

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

examples/image/image-example.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ const url3 = 'https://i.giphy.com/media/5wWf7HapUvpOumiXZRK/giphy.gif'
88
// Read different images from a url
99
const image1 = await readImageFromURL(url1)
1010
// (bytes, path, name)
11-
await writeImage(image1.bytes, './examples/image/', 'cat.jpeg') // custom name
11+
await writeImage(image1.bytes, './examples/image/cat.jpeg') // custom name
1212

1313
const image2 = await readImageFromURL(url2)
14-
await writeImage(image2.bytes, './examples/image/', image2.name) // default image name
14+
await writeImage(image2.bytes, `./examples/image/${image2.name}`) // default image name
1515

1616
const image3 = await readImageFromURL(url3)
17-
await writeImage(image3.bytes, './examples/image/', image3.name)
17+
await writeImage(image3.bytes, `./examples/image/${image3.name}`)
1818

1919
// Image manipulation example - reading from a file
2020
const bytes = await readImageFromFile('./examples/image/cat.jpeg') // local file
2121
const image = await Image.decode(bytes);
2222
image.crop(image.width/4, image.height/4, image.width/2, image.height/2); // x, y, width, height
2323
const newImageBytes = await image.encode()
24-
await writeImage(newImageBytes, './examples/image/', 'cat-cropped.jpeg')
24+
await writeImage(newImageBytes, './examples/image/cat-cropped.jpeg')

examples/json/json-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readJSON, writeJSON } from '../../src/json.ts' // replace with latest library https://deno.land/x/flat@0.0.x/mod.ts
22

3-
const json = await readJSON('./examples/json/data.json') as any
3+
const json = await readJSON('./examples/json/data.json')
44

55
// a New custom json to save
66
const newData = {

src/image.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { mime } from "https://cdn.deno.land/mimetypes/versions/v1.0.0/raw/mod.ts
22
import { urlParse } from 'https://cdn.deno.land/url_parse/versions/1.0.0/raw/mod.ts';
33
import { basename } from "https://deno.land/std@0.92.0/path/mod.ts";
44

5-
export async function readImageFromURL(url: string) {
5+
export async function readImageFromURL(url: string): Promise<{ bytes: Uint8Array; name: string; }> {
66
const response = await fetch(url); // fetch an image
77
const mimeType = response.headers.get('content-type');
88
const imageBytes = new Uint8Array(await response.arrayBuffer());
@@ -19,12 +19,11 @@ export async function readImageFromURL(url: string) {
1919
return { bytes: imageBytes, name: defaultImageName }
2020
}
2121

22-
export async function readImageFromFile(path: string) {
22+
export async function readImageFromFile(path: string): Promise<Uint8Array> {
2323
const bytes = await Deno.readFile(path) // local file
2424
return bytes
2525
}
2626

27-
export async function writeImage(imageBytes: Uint8Array, path: string, name?: string) {
28-
const imagePath = `${path}${name}`
29-
await Deno.writeFile(imagePath, imageBytes);
27+
export async function writeImage(imageBytes: Uint8Array, path: string) {
28+
await Deno.writeFile(path, imageBytes);
3029
}

0 commit comments

Comments
 (0)