Node.js로 워터마킹 기능을 구현하는 방법
Node.js로 워터마킹 기능을 구현하는 방법중 두가지를 설명드리겠습니다.
1. 이미지에 텍스트 워터마크 추가하기:
- `jimp` 라이브러리를 사용하여 이미지를 로드합니다.
- `jimp`의 `print` 메서드를 사용하여 이미지에 텍스트 워터마크를 추가합니다.
- 수정된 이미지를 저장하거나 출력합니다.
[code]
const Jimp = require('jimp');
// 이미지 로드
Jimp.read('original.jpg')
.then(image => {
// 텍스트 워터마크 추가
image.print(
Jimp.loadFont(Jimp.FONT_SANS_16_BLACK),
10, // x 좌표
10, // y 좌표
'Watermark Text' // 텍스트 내용
);
// 수정된 이미지 저장
image.write('watermarked.jpg');
})
.catch(error => {
console.error(error);
});
[/code]
2. 이미지에 로고 워터마크 추가하기:
- `sharp` 라이브러리를 사용하여 이미지를 로드합니다.
- `sharp`의 `composite` 메서드를 사용하여 이미지에 로고 워터마크를 추가합니다.
- 수정된 이미지를 저장하거나 출력합니다.
[code]
const sharp = require('sharp');
// 이미지 로드
sharp('original.jpg')
.composite([
{
input: 'logo.png', // 로고 이미지 경로
gravity: 'southeast', // 로고 위치
opacity: 0.8 // 로고 투명도
}
])
.toFile('watermarked.jpg')
.then(() => {
console.log('Watermark added successfully');
})
.catch(error => {
console.error(error);
});
[/code]
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4946 | node.js | 6년 전 | 2610 | ||
| 4945 | node.js | 6년 전 | 2382 | ||
| 4944 | node.js | 6년 전 | 2520 | ||
| 4943 | node.js | 6년 전 | 2272 | ||
| 4942 | node.js | 6년 전 | 2250 | ||
| 4941 | node.js | 6년 전 | 2719 | ||
| 4940 | node.js | 6년 전 | 1867 | ||
| 4939 | node.js | 6년 전 | 1995 | ||
| 4938 | node.js | 6년 전 | 2459 | ||
| 4937 | node.js | 6년 전 | 2250 | ||
| 4936 | node.js | 6년 전 | 2322 | ||
| 4935 | node.js | 6년 전 | 2136 | ||
| 4934 | node.js | 6년 전 | 2441 | ||
| 4933 | node.js | 6년 전 | 2247 | ||
| 4932 | node.js | 6년 전 | 2687 | ||
| 4931 | node.js | 6년 전 | 2070 | ||
| 4930 | node.js | 6년 전 | 1999 | ||
| 4929 | node.js | 6년 전 | 8632 | ||
| 4928 | node.js | 6년 전 | 3749 | ||
| 4927 | node.js | 6년 전 | 2394 | ||
| 4926 | node.js | 6년 전 | 2504 | ||
| 4925 | node.js | 6년 전 | 2083 | ||
| 4924 | node.js | 6년 전 | 3374 | ||
| 4923 | node.js | 6년 전 | 2221 | ||
| 4922 | node.js | 6년 전 | 1989 | ||
| 4921 | node.js | 6년 전 | 2046 | ||
| 4920 | node.js | 6년 전 | 1765 | ||
| 4919 | node.js | 6년 전 | 2031 | ||
| 4918 | node.js | 6년 전 | 2179 | ||
| 4917 | node.js | 6년 전 | 2395 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기