Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
(cherry picked from commit a651044591ecfd20409e5e004aa71c6da0561386)

# Conflicts:
#	packages/core/src/index.ts
  • Loading branch information
hipstersmoothie committed Mar 21, 2024
1 parent 3d24bfd commit 44d103d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"description": "The jimp monorepo.",
"repository": "jimp-dev/jimp",
"author": "Andrew Lisowski <lisowski54@gmail.com>",
"engines": {
"node": ">=18"
},
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev",
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"devDependencies": {
"@jimp/config-eslint": "workspace:*",
"@jimp/config-typescript": "workspace:*",
"@types/file-type": "^10.9.1",
"eslint": "^8.57.0",
"tshy": "^1.12.0",
"typescript": "^5.4.2",
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,18 @@ export class Jimp<
> implements JimpClass
{
static plugins: JimpPlugin[] = [];
/**
* Plugins that add image formats
*/
static formatPlugins: JimpFormat[] = [];
/**
* Formats that can be used with Jimp
*/
static formats: Format[] = [];

/**
* The bitmap data of the image
*/
bitmap: Bitmap = emptyBitmap;
methods: MethodMap = {} as MethodMap;
formats: Format<SupportedMimeTypes>[] = [];
Expand Down
7 changes: 6 additions & 1 deletion packages/jimp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import blit from "@jimp/plugin-blit";
import png from "@jimp/js-png";

export const Jimp = JimpCustom
// .addFormat(png)
// Formats
.addFormat(png)
// Plugins
.plugin(blit)
.plugin(crop);

const image = new Jimp();

image
// doesn't work because blit is added first
.blit({ src: image, x: 0, y: 0 })
.crop(0, 0, image.bitmap.width, image.bitmap.height)
.blit({ src: image, x: 0, y: 0 })
Expand All @@ -21,4 +24,6 @@ image
image
.crop(0, 0, image.bitmap.width, image.bitmap.height)
.blit({ src: image, x: 0, y: 0 })
// doesn't work because becuase of type returned from crop?
// maybe its the same issue as above?
.crop(0, 0, image.bitmap.width, image.bitmap.height);
34 changes: 18 additions & 16 deletions plugins/plugin-blit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { JimpClass } from "@jimp/types";
import { limit255, scan } from "@jimp/utils";

export interface BlitOptions<I extends JimpClass> {
/** This image to blit on to the current image */
src: I;
/** the x position to blit the image */
x: number;
/** the y position to blit the image */
y: number;
/** the x position from which to crop the source image */
srcX?: number;
/** the y position from which to crop the source image */
srcY?: number;
/** the width to which to crop the source image */
srcW?: number;
/** the height to which to crop the source image */
srcH?: number;
}

/**
* Blits a source image on to this image
*/
Expand All @@ -14,22 +31,7 @@ function blit<I extends JimpClass>(
srcY = 0,
srcW = src.bitmap.width,
srcH = src.bitmap.height,
}: {
/** This image to blit on to the current image */
src: I;
/** the x position to blit the image */
x: number;
/** the y position to blit the image */
y: number;
/** the x position from which to crop the source image */
srcX?: number;
/** the y position from which to crop the source image */
srcY?: number;
/** the width to which to crop the source image */
srcW?: number;
/** the height to which to crop the source image */
srcH?: number;
},
}: BlitOptions<I>,
) {
if (!("bitmap" in src)) {
throw new Error("The source must be a Jimp image");
Expand Down
16 changes: 10 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 44d103d

Please sign in to comment.