npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@knowcode/imgfetch

v0.1.0

Published

Reliable image downloader CLI that works with any website

Readme

📸 @knowcode/imgfetch

Download images from anywhere. Even the tricky sites.

npm version License: MIT Node.js Version

A powerful CLI tool that combines multiple strategies to reliably download images from any website, including those with anti-bot protection, dynamic content, and authentication requirements.

FeaturesInstallationQuick StartStrategiesExamplesAPIFAQ


🎯 Why imgfetch?

Ever tried to download an image only to get blocked by anti-bot measures? Or struggled with JavaScript-rendered content? imgfetch solves these problems by intelligently selecting the right approach for each URL.

# Just works™
imgfetch https://linkedin.com/in/john-doe --strategy browser -o profile.jpg

✨ Features

🚀 Smart Detection

Automatically chooses the best download strategy based on URL patterns and site requirements.

🤖 Anti-Bot Bypass

Uses puppeteer-extra-plugin-stealth to avoid detection on protected sites.

📦 Batch Processing

Download multiple images efficiently with a single command.

🔄 Automatic Fallback

If one method fails, automatically tries alternative strategies.

📦 Installation

Global Installation (Recommended)

npm install -g @knowcode/imgfetch

Local Installation

npm install @knowcode/imgfetch

Requirements

  • Node.js 16.0.0 or higher
  • npm or yarn

🚀 Quick Start

Basic Usage

# Download a simple image
imgfetch https://example.com/photo.jpg

# Save with custom filename
imgfetch https://example.com/photo.jpg -o my-image.jpg

# Force browser strategy for dynamic content
imgfetch https://instagram.com/p/ABC123 --strategy browser

Batch Download

Create a file urls.txt:

https://example.com/image1.jpg
https://linkedin.com/in/user
https://unsplash.com/photos/abc123

Then run:

imgfetch batch urls.txt --output-dir ./images/

🎨 Strategies

Direct Strategy

Best for: Static images, CDN links, direct URLs

imgfetch https://cdn.example.com/image.png --strategy direct
  • ⚡ Fastest method
  • 📦 Minimal resource usage
  • ✅ Works with most image hosting services

Browser Strategy (Puppeteer)

Best for: Social media, JavaScript-rendered content

imgfetch https://linkedin.com/in/user --strategy browser
  • 🛡️ Bypasses anti-bot protection
  • 🔍 Handles dynamic content
  • 🍪 Maintains session state

Playwright Strategy

Best for: Complex sites, when Puppeteer fails

imgfetch https://complex-site.com/image --strategy playwright
  • 🌐 Cross-browser support
  • 🔧 Alternative automation engine
  • 🎭 Better handling of modern web apps

📖 Examples

Download LinkedIn Profile Pictures

imgfetch https://linkedin.com/in/john-doe \
  --strategy browser \
  -o john-doe-profile.jpg

Extract Images from Instagram Posts

imgfetch https://instagram.com/p/ABC123XYZ \
  --strategy browser \
  --timeout 45

Batch Download with Mixed Sources

# Create urls.txt with various image sources
cat > urls.txt << EOF
https://pbs.twimg.com/profile_images/123/abc.jpg
https://linkedin.com/in/jane-doe
https://github.com/user.png
EOF

# Download all images
imgfetch batch urls.txt --output-dir ./profile-pics/

JSON Output for Automation

# Get structured output for scripting
result=$(imgfetch https://example.com/img.jpg --json)
echo $result | jq '.path'

🧩 API Usage

Node.js Integration

const ImageFetcher = require('@knowcode/imgfetch');

async function downloadImage() {
  const fetcher = new ImageFetcher({
    strategy: 'auto',
    timeout: 30000
  });

  try {
    const result = await fetcher.fetch(
      'https://example.com/image.jpg',
      './output.jpg'
    );
    
    console.log('Success!', result);
    // {
    //   success: true,
    //   strategy: 'direct',
    //   path: './output.jpg',
    //   size: 245632,
    //   mimeType: 'image/jpeg'
    // }
  } catch (error) {
    console.error('Failed:', error.message);
  } finally {
    await fetcher.close();
  }
}

Advanced Configuration

const fetcher = new ImageFetcher({
  strategy: 'browser',  // Force specific strategy
  timeout: 60000,       // 60 second timeout
  retries: 5,          // Number of retry attempts
});

🎛️ Command Line Options

| Option | Short | Description | Default | |--------|-------|-------------|---------| | --output | -o | Output file path | Auto-generated | | --strategy | -s | Download strategy (auto, direct, browser, playwright) | auto | | --timeout | -t | Timeout in seconds | 30 | | --json | | Output as JSON | false | | --quiet | -q | Suppress progress output | false | | --help | -h | Show help | | | --version | -V | Show version | |

🔧 Configuration

Environment Variables

# Set default timeout
export IMGFETCH_TIMEOUT=60

# Set default output directory
export IMGFETCH_OUTPUT_DIR=./downloads

Custom Headers

const fetcher = new ImageFetcher({
  headers: {
    'User-Agent': 'Custom User Agent',
    'Referer': 'https://example.com'
  }
});

❓ FAQ

Why does it download the wrong image from some sites?

Some sites load multiple images. imgfetch tries to identify the main image, but you might need to use browser DevTools to find the specific image URL.

Can it handle sites that require login?

Currently, imgfetch doesn't support authentication. For sites requiring login, you'll need to download images manually or use browser automation with saved cookies.

Why is browser strategy slow?

Browser automation launches a real browser instance, which takes time. Use direct strategy when possible for better performance.

How do I download from sites with CAPTCHA?

CAPTCHA-protected sites require manual intervention. imgfetch can't automatically solve CAPTCHAs.

🛠️ Troubleshooting

"No suitable image found"

  • The page might not contain images
  • Try using --strategy browser for dynamic content
  • Check if the URL requires authentication

"All strategies failed"

  • Verify the URL is accessible in a regular browser
  • Check your internet connection
  • Some sites may have strong anti-bot protection

Installation Issues

# Clear npm cache
npm cache clean --force

# Install with verbose logging
npm install -g @knowcode/imgfetch --verbose

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments


Made with ❤️ by knowcode

Report BugRequest Feature