MCPcopy
hub / github.com/jimp-dev/jimp / createJimp

Function createJimp

packages/core/src/index.ts:136–785  ·  view source on GitHub ↗
({
  plugins: pluginsArg,
  formats: formatsArg,
}: {
  /** Plugins that add methods to the created Jimp class */
  plugins?: Methods;
  /** Image formats the Jimp class should support */
  formats?: Formats;
} = {})

Source from the content-addressed store, hash-verified

134 * Create a Jimp class that support the given image formats and methods
135 */
136export function createJimp<
137 Methods extends JimpPlugin[],
138 Formats extends JimpFormat[],
139>({
140 plugins: pluginsArg,
141 formats: formatsArg,
142}: {
143 /** Plugins that add methods to the created Jimp class */
144 plugins?: Methods;
145 /** Image formats the Jimp class should support */
146 formats?: Formats;
147} = {}) {
148 type ExtraMethodMap = JimpInstanceMethods<
149 InstanceType<typeof CustomJimp>,
150 UnionToIntersection<Methods[number]>
151 >;
152 type SupportedMimeTypes = ReturnType<Formats[number]>["mime"];
153 type MimeTypeToExportOptions = CreateMimeTypeToExportOptions<
154 ReturnType<Formats[number]>
155 >;
156 type MimeTypeToDecodeOptions = CreateMimeTypeToDecodeOptions<
157 ReturnType<Formats[number]>
158 >;
159 type ExtensionToMimeType = CreateExtensionToMimeType<SupportedMimeTypes>;
160
161 const plugins = pluginsArg || [];
162 const formats = (formatsArg || []).map((format) => format());
163
164 const CustomJimp = class Jimp implements JimpClass {
165 /**
166 * The bitmap data of the image
167 */
168 bitmap: Bitmap = emptyBitmap;
169
170 /** Default color to use for new pixels */
171 background = 0x00000000;
172
173 /** Formats that can be used with Jimp */
174 formats: Format<any>[] = [];
175
176 /** The original MIME type of the image */
177 mime?: string;
178
179 constructor(options: JimpConstructorOptions = emptyBitmap) {
180 // Add the formats
181 this.formats = formats;
182
183 if ("data" in options) {
184 this.bitmap = options;
185 } else {
186 this.bitmap = {
187 data: Buffer.alloc(options.width * options.height * 4),
188 width: options.width,
189 height: options.height,
190 };
191
192 if (options.color) {
193 this.background =

Callers 15

index.test.tsFile · 0.90
webp-example.tsxFile · 0.90
index.tsFile · 0.90
crop.test.tsFile · 0.90
autocrop.test.tsFile · 0.90
index.test.tsFile · 0.90
index.node.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…