Tutorials

Convert JPG/PNG Image to Pixelated & Blurred Image Using Node.js ImageMagick Express.js

npm init -y
npm i express
npm i multer

Just make a uploads directory where all the input image files will be stored

index.js

const express = require('express')

const multer = require('multer')

const {exec} = require('child_process')

const path = require('path')

const app = express()

var storage = multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, 'uploads')
    },
    filename: function (req, file, cb) {
      cb(null, Date.now() + path.extname(file.originalname)) //Appending extension
    }
  })
  
var upload = multer({ storage: storage }).single('file')

app.post('/pixelatedimage',(req,res) => {
    let output = Date.now() + "output.jpg"
    upload(req,res,(err) => {
        if(err){
            console.log("Error in uploading file")
        }else{
            console.log(req.file.path)

            exec(`magick convert -scale 10% -scale 1000% ${req.file.path} ${output}`,(err,stdout,stderr) => {
                if(err){
                    console.log("Error takes place in processing image")
                }else{
                    res.download(output,(err) => {
                        
                    })
                }
            })
        }
    })
})

app.get('/',(req,res) => {
    res.sendFile(__dirname + "/index.html")
})

app.listen(5000,() => {
    console.log("App is listening on port 5000")
})

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image to Pixelated Image</title>
</head>
<body>
    <form action="/pixelatedimage" method="post" enctype="multipart/form-data">
        <input type="file" name="file" id="" required>
        <button>Download Pixelated Image</button>
    </form>
</body>
</html>

Run the Project

node index.js
Furqan

Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.

Recent Posts

MiniMax-M1 vs GPT-4o vs Claude 3 Opus vs LLaMA 3 Benchmarks

MiniMax-M1 is a new open-weight large language model (456 B parameters, ~46 B active) built with hybrid…

August 31, 2025

How to Use Husky with npm to Manage Git Hooks

Managing Git hooks manually can quickly become tedious and error-prone—especially in fast-moving JavaScript or Node.js…

August 31, 2025

How to Use Lefthook with npm to Manage Git Hooks

Git hooks help teams enforce code quality by automating checks at key stages like commits…

August 31, 2025

Lefthook vs Husky: Which Git Hooks Tool is Better? 2025

Choosing the right Git hooks manager directly impacts code quality, developer experience, and CI/CD performance. Lefthook and Husky are…

August 31, 2025

Llama 3.1 vs GPT-4 Benchmarks

We evaluated the performance of Llama 3.1 vs GPT-4 models on over 150 benchmark datasets…

July 24, 2024

Transforming Manufacturing with Industrial IoT Solutions and Machine Learning

The manufacturing industry is undergoing a significant transformation with the advent of Industrial IoT Solutions.…

July 6, 2024