Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pereira299 committed Mar 23, 2023
1 parent 621c7ce commit 2fed521
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 109 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cSpell.words": [
"euclidian",
"marvin"
"marvin",
"thresholding"
]
}
139 changes: 127 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,48 +45,163 @@ Before load image you need create a new Marvin instance
## Features
### Blur
```
// gaussian blur
marvin.gaussianBlur(10)
```
### Color
```
// Average color
marvin.averageColor()
// Black and white
marvin.blackAndWhite(50)
// Brightness and Contrast
marvin.brightnessAndContrast(50, 50)
// Emboss
marvin.emboss()
// Gray scale
marvin.grayScale()
// Heat map
marvin.heatMap(10)
// invert colors
marvin.invertColors()
// Posterization
marvin.posterize(10);
// Thresholding
marvin.thresholding(10);
// Serpia
marvin.sepia(5);
// Color channels
marvin.colorChannel("#fefc58", 20);
```
### Combine
```
// Combine by alpha
marvin.combineByAlpha(image3, 10, 20)
// Merge photos
marvin.mergePhotos([image3], 10);
```
### Corner
```
// Moravec corner detector
marvin.moravec(5, 500);
```
### Draw
```
// Circle
marvin.drawCircle(10, 10, 20);
// Regular curve
marvin.drawCurve(10, 10, 20, 20, 30);
// Quadratic curve
marvin.drawQuadraticCurve(10, 10, 20, 20, 30, 30);
// Cubic curve
marvin.drawCubicCurve(10, 10, 20,20, 25,35, 30,30);
// Ellipse
marvin.drawEllipse(10, 10, 20, 20);
// Line
marvin.drawLine(10, 10, 20, 20);
// Rectangle
marvin.drawRect(10, 10, 20, 20);
// Star
marvin.drawStar(10, 10, 20, 20);
// Start path
marvin.pathStart(10, 10);
// Line to
marvin.lineTo(10, 10);
// Quadratic curve to
marvin.quadraticCurveTo(10, 10, 20, 20);
// Cubic curve to
marvin.cubicCurveTo(10, 10, 20, 20, 30, 30);
// Regular curve to
marvin.curveTo(10, 10, 20, 20);
```
### Edge
```
// Prewitt edge detector
marvin.prewitt(1);
// Sobel edge detector
marvin.sobel(1);
// Canny edge detector
marvin.canny(100, 500);
```
### Pattern
### Text
```
// Find text
marvin.findTextRegions(10, 20, 5, 40);
// Write text on image
marvin.write("Exemple", 10, 20);
```
### Restoration
```
// Noise reduction
marvin.noiseReduction(10);
```
### Segment
```
// Crop image
marvin.crop(10, 20, 30, 40);
```
### Transform
```
// Flip horizontal
marvin.flipHorizontal();
// Flip vertical
marvin.flipVertical();
// Flip horizontal and vertical
marvin.flipBoth();
// Rotate
marvin.rotate(90);
// Scale
marvin.scale(2, 2);
```
### Get or save
```
// Get back Marvin image after process
marvin.flipVertical().output();
// Save image as JPEG or PNG
marvin.save("output/image.png");
```

### Chains
```
// Easily run as many functions as you want with function chains
marvin.flipBoth()
.scale(2, 2)
.noiseReduction(10)
.drawRect(10, 10, 20, 20)
.save("out")
```
**IMPORTANT!** Chains run only in functions that return a marvin instance

This project is a fork of [MarvinJ](http://marvinj.org/)

102 changes: 13 additions & 89 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,15 @@
import MarvinImage from "./src/image/MarvinImage";
import Marvin from "./src/MarvinFramework";
import * as fs from "fs";
import marvinJSUtils from "./src/MarvinJSUtils";

const url =
"https://cursinhoparamedicina.com.br/wp-content/uploads/2022/10/Paisagem-1.jpg";
const url2 = "https://marvinproject.net/images/pluginsOut/noiseReductionIn.jpg";
const url3 =
"https://www.psicologo.com.br/wp-content/uploads/sou-uma-pessoa-boa-ou-nao.jpg";
const url4 = "https://marvinj.org/images/cheetah.jpg";

const main = async () => {
// const image = await new MarvinImage(635, 424).load(url);
// const image2 = await new MarvinImage(240, 320).load(url2);
console.time("load");
const image3 = await new MarvinImage(240, 320).load(url4);
console.timeEnd("load");
// averageColor
// console.log(new Marvin(image).averageColor())
// blackAndWhite
// new Marvin(image).blackAndWhite(25).save("output/blackAndWhite.png");
// brightnessAndContrast
// new Marvin(image).brightnessAndContrast(50, 50).save("output/brightnessAndContrast.png");
// colorChannel
// new Marvin(image).colorChannel(50, 50, 150).save("output/colorChannel.png");
// combineByAlpha
// new Marvin(image).combineByAlpha(image, 200, 200).save("output/combineByAlpha.png");
// crop
// new Marvin(image).crop(50, 50,200,200).save("output/crop.png");
// morphologicalDilation
// new Marvin(image).morphologicalDilation([[0, 0, 0], [0, 0, 0]]).save("output/morphologicalDilation.png");
// emboss
// new Marvin(image3).emboss().save("output/emboss.png");
// morphologicalErosion
// new Marvin(image).morphologicalErosion([[0, 0, 0], [0, 0, 0]]).save("output/morphologicalErosion.png");
// findTextRegions
// console.log(new Marvin(image).findTextRegions(10, 20,1,1));
// floodfillSegmentation
// console.log(new Marvin(image).floodfillSegmentation());
// gaussianBlur
// new Marvin(image).gaussianBlur(10).save("output/gaussianBlur.png");
// grayScale
// new Marvin(image3).grayScale().save("output/grayScale.png");
// invertColors
// new Marvin(image).invertColors().save("output/invertColors.png");
// mergePhotos
// new Marvin(image).mergePhotos([image], 0.5).save("output/mergePhotos.png");
// moravec
// new Marvin(image).blackAndWhite(15).emboss().save("output/emboss2.png");
// x: 156 y: 491
// console.log(new Marvin(image3).moravec(3, 15000, true));
// prewitt
// new Marvin(image3).prewitt(1).save("output/prewitt.png");
// scale
// new Marvin(image).scale(50,20).save("output/scale.png");
// sepia
// new Marvin(image).sepia(20).save("output/sepia.png");
// thresholding
// new Marvin(image3).thresholding(100, true).save("output/thresholding.png");
// halftoneErrorDiffusion
// new Marvin(image).halftoneErrorDiffusion().save("output/halftoneErrorDiffusion.png");
// Flip horizontal
// new Marvin(image).flipHorizontal().save("output/flipHorizontal.png");
// Flip vertical
// new Marvin(image).flipVertical().save("output/flipVertical.png");
// Flip both
// new Marvin(image).flipBoth().save("output/flipDiagonal.png");
// Rotate 90
// new Marvin(image).rotate(-90).save("output/rotate-90.png");
// Rotate 45
// new Marvin(image).rotate(45).save("output/rotate45.png");
// Noise Reduction
// new Marvin(image2).noiseReduction().save("output/noiseReduction.png");
// Remove Background
// new Marvin(image3).emboss().blackAndWhite(100).noiseReduction(5, 0.8).save("output/emboss3.png");
// new Marvin(image3).emboss().blackAndWhite(100).blackAndWhite(25).save("output/edge.png");
// new Marvin(image3).grayScale().gaussianBlur(5).sobel(5).thresholding(1).invertColors().save("output/edge.png");
// new Marvin(image3).grayScale().gaussianBlur(5).sobel(5).thresholding(10).blackAndWhite(10).invertColors().heatMap(5).save("output/heatMap.png");
// new Marvin(image3).emboss().invertColors().gaussianBlur(5).blackAndWhite(20).save("output/canny.png");
// new Marvin(image3).posterize(10).gaussianBlur(5).emboss().save("output/posterize.png");
// new Marvin(image3).drawRect(20, 20, 120, 50, "#ff0000", 20).save("output/drawLine.png");
// new Marvin(image3)
// .drawCubicCurve(100, 100, 300, 100, 110, 400, 150, 50, {
// color: "#ff0000",
// weight: 2,
// })
// .save("output/drawCubicCurve.png");
};
import MarvinImage from "./src/image/MarvinImage";
import MarvinColorModelConverter from "./src/color/MarvinColorModelConverter";
import MarvinColor from "./src/MarvinColor";
import MarvinMath from "./src/math/MarvinMath";
import MarvinJSUtils from "./src/MarvinJSUtils";

main();
export default Marvin;
export {
MarvinImage,
MarvinColorModelConverter as MarvinColorConverter,
MarvinColor,
MarvinMath,
MarvinJSUtils as MarvinUtils,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marvin-ts",
"version": "1.2.0",
"version": "1.1.0",
"description": "typescript image processing framework",
"main": "index.ts",
"repository": "https://github.com/pereira299/marvinj.git",
Expand Down
12 changes: 6 additions & 6 deletions src/MarvinFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,16 +751,16 @@ export default class Marvin {
y2 = this.image.getHeight() + 10,
dotX = this.image.getWidth(),
dotY = this.image.getHeight(),
{ color = "#000000", weight = 1 }
options = { color: "#000000", weight: 1 }
) {
const drawQuadraticCurve = new Curve();
Curve.setAttribute("x1", x1);
Curve.setAttribute("y1", y1);
Curve.setAttribute("x2", x2);
Curve.setAttribute("y2", y2);
Curve.setAttribute("dot1", { x: dotX, y: dotY });
Curve.setAttribute("color", color);
Curve.setAttribute("weight", weight);
Curve.setAttribute("color", options.color);
Curve.setAttribute("weight", options.weight);
Curve.setAttribute("type", "quadratic");
this.image = drawQuadraticCurve.process(this.image);
return this;
Expand Down Expand Up @@ -795,7 +795,7 @@ export default class Marvin {
dot1Y = this.image.getHeight(),
dot2X = this.image.getWidth(),
dot2Y = this.image.getHeight(),
{ color = "#000000", weight = 1 }
options = { color: "#000000", weight: 1 }
) {
const drawCubicCurve = new Curve();
Curve.setAttribute("x1", x1);
Expand All @@ -804,8 +804,8 @@ export default class Marvin {
Curve.setAttribute("y2", y2);
Curve.setAttribute("dot1", { x: dot1X, y: dot1Y });
Curve.setAttribute("dot2", { x: dot2X, y: dot2Y });
Curve.setAttribute("color", color);
Curve.setAttribute("weight", weight);
Curve.setAttribute("color", options.color);
Curve.setAttribute("weight", options.weight);
Curve.setAttribute("type", "cubic");
this.image = drawCubicCurve.process(this.image);
return this;
Expand Down
1 change: 1 addition & 0 deletions src/image/MarvinImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default class MarvinImage {
resolve(res);
};
this.image.src = base64;

});
}

Expand Down
22 changes: 22 additions & 0 deletions src/plugins/pattern/Write.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { registerFont } from "canvas";
import fetch from "node-fetch";

export default class Write {
async downloadFont(fontLink: string) {
const response = await fetch(fontLink);
const text = await response.text();
const url = text.match(/url\((.*?)\)/)[1].replace(/['"]/g, "");
const fontBuffer = await fetch(url).then((res) =>
res.arrayBuffer()
);
return fontBuffer;
}

// Registra a fonte Roboto do Google Fonts
async registerGoogleFont(url: string) {
const fontBuffer = await this.downloadFont(url);
const font = Buffer.from(fontBuffer).toString("base64");
const fontName = url.match(/family=(.*?)&/)[1];
registerFont(fontName, { family: fontName, style: "normal", font: font });
}
}
Binary file removed test.png
Binary file not shown.
Loading

0 comments on commit 2fed521

Please sign in to comment.