-
-
Notifications
You must be signed in to change notification settings - Fork 755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add red or purple color text on the image? #537
Comments
I think you have to find a bitmap font that is already colored. Printing seems to work by having a bitmap font file that maps characters to a special png with all the characters on it already. You might have to play around with a few tools to get your fonts to have color some examples after a little googling https://www.colorfonts.wtf/ You could try using the tool mentioned in the readme http://kvazars.com/littera/ to create a color font. A bunch of other tools are also here https://github.com/libgdx/libgdx/wiki/Hiero |
@hipstersmoothie Many thanks |
U can use Hiero for change color and size |
You don't have to create a color font.
If you need a non-transparent background then create one as a separate image and blit it with the text image:
|
Works perfectly. Thank you |
Hello can you tell me where to insert this line of code. |
import jimp from 'jimp'
async function main() {
const font = await jimp.loadFont(jimp.FONT_SANS_32_BLACK)
const image = await jimp.read('test1.jpg')
image.print(font, 0, 0, {
text: 'Hello, Dexter Morgan!',
alignmentX: jimp.HORIZONTAL_ALIGN_CENTER,
alignmentY: jimp.VERTICAL_ALIGN_MIDDLE
},
image.getWidth(),
image.getHeight()
)
image.write('test2.jpg')
}
main() |
@abdel78900 @gugamacedo This stackOverflow answer has this example: Jimp.read('testImage.jpg', (err, baseImage) => {
if (err) throw err;
let textImage = new Jimp(1000,1000, 0x0, (err, textImage) => {
//((0x0 = 0 = rgba(0, 0, 0, 0)) = transparent)
if (err) throw err;
})
Jimp.loadFont(Jimp.FONT_SANS_32_BLACK).then(font => {
textImage.print(font, 0, 0, "My Text")
textImage.color([{ apply: 'xor', params: [#00ff00] }]);
image.blit(textImage, 0, 0)
image.write('testOutput.jpg'); // save
});
}); |
@abdel78900 @maitrungduc1410 @LukaszWiktor |
If any changes to the docs are needed and wants to submit a PR to fix I'm able to review and merge! |
var Jimp = require('jimp');
Jimp.read('test.jpg', (err, image) => {
if (err) throw err;
Jimp.loadFont(Jimp.FONT_SANS_32_BLACK).then(function(font) {
image.print(font, 10, 10, 'Hello world!');
image.write('lena-small-bw.jpg');
});
});
I can use the above source to write 'Hello world!' on the test.jpg picture, however, it seems that Jimp only can write white or black text on the image rather than other color: for example, red or purple. How to add red or purple color text on the image?
Any help is much appreciated!!!
The text was updated successfully, but these errors were encountered: