
Research
/Security News
DuckDB npm Account Compromised in Continuing Supply Chain Attack
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
wp-sharp-image
Advanced tools
High-performance image processing for WordPress using Sharp and Bun. This module monitors the WordPress uploads directory and automatically processes new images according to WordPress image size configurations, providing a significant performance improvement over PHP-based image processing.
Navigate to the module directory:
cd wp-sharp-image
Install dependencies:
bun install
Run the interactive setup wizard:
bun run configure
This will:
Install dependencies:
cd wp-sharp-image
bun install
Check system requirements:
bun run check
Configure the application:
cp config.example.js config.js
Edit config.js
with your WordPress installation paths.
Test the configuration:
bun run start
Check service status:
bun run status
Copy config.example.js
to config.js
and modify according to your setup:
The system uses wp-cli to interact with WordPress, so no database credentials are needed. WP-CLI uses WordPress's own database configuration from wp-config.php
.
You can pass additional arguments to all wp-cli commands via the wpCliArgs
array:
wordpress: {
// ... other settings
wpCliArgs: [
'--url=example.com', // Required for multisite
'--user=admin', // Run commands as specific user
'--skip-plugins', // Skip plugin loading for performance
'--skip-themes', // Skip theme loading for performance
'--debug', // Enable wp-cli debug output
'--quiet', // Suppress informational messages
'--allow-root' // Allow running as root user
]
}
Common Use Cases:
--url=your-site.com
to target specific site--skip-plugins
and --skip-themes
to speed up commands--debug
for detailed wp-cli output--quiet
to reduce log verbositywordpress: {
rootPath: '/path/to/wordpress',
uploadsPath: '/path/to/wordpress/wp-content/uploads',
contentPath: '/path/to/wordpress/wp-content',
// Additional wp-cli arguments (optional)
wpCliArgs: [
'--url=example.com', // For multisite
'--user=admin', // Run as specific user
'--skip-plugins', // Skip plugin loading for performance
'--quiet' // Suppress informational messages
]
}
images: {
quality: {
jpeg: 90,
webp: 80,
png: 100,
avif: 75
},
progressive: true,
optimize: true,
modernFormats: {
webp: true,
avif: false
},
concurrency: 4,
backupOriginals: true
}
bun run dev
bun run start
npm install -g pm2
cp supervisor/pm2.config.cjs ecosystem.config.cjs
# Edit ecosystem.config.cjs to update paths
pm2 start ecosystem.config.cjs --env production
pm2 save
pm2 startup
sudo cp supervisor/supervisor.conf /etc/supervisor/conf.d/wp-sharp-image.conf
# Edit the configuration file to update paths and user
sudo nano /etc/supervisor/conf.d/wp-sharp-image.conf
Then reload supervisor:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start wp-sharp-image
sudo cp supervisor/systemd.service /etc/systemd/system/wp-sharp-image.service
# Edit the service file to update paths and user
sudo nano /etc/systemd/system/wp-sharp-image.service
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable wp-sharp-image
sudo systemctl start wp-sharp-image
Add this to your WordPress functions.php
or a plugin:
// Disable WordPress image resizing
add_filter('intermediate_image_sizes_advanced', '__return_empty_array');
// Optional: Remove default image sizes
add_filter('intermediate_image_sizes', function($sizes) {
return [];
});
// Prevent WordPress from generating thumbnails on upload
add_filter('wp_generate_attachment_metadata', function($metadata, $attachment_id) {
// Let Sharp handle the processing
return $metadata;
}, 10, 2);
Check the logs to ensure images are being processed:
tail -f logs/wp-sharp-image.log
dev/wp-sharp-image/
βββ index.js # Main application entry point
βββ setup.js # Interactive setup wizard
βββ package.json # Dependencies and scripts
βββ config.example.js # Example configuration
βββ config.js # Your configuration (gitignored)
βββ README.md # This file
βββ src/
β βββ Database.js # WordPress data access via wp-cli
β βββ ImageProcessor.js # Sharp image processing logic
β βββ FileWatcher.js # File system monitoring
β βββ Logger.js # Logging utilities
β βββ Prompt.js # User interaction utilities
βββ scripts/
β βββ check-requirements.js # System requirements checker
β βββ service-status.js # Service status checker
βββ logs/ # Log files (auto-created)
β βββ wp-sharp-image.log # Main log file
β βββ exceptions.log # Uncaught exceptions
β βββ rejections.log # Unhandled rejections
βββ supervisor/ # Service configuration examples
βββ supervisor.conf # Supervisor configuration
βββ systemd.service # systemd service file
βββ pm2.config.js # PM2 configuration
The service provides comprehensive monitoring and statistics:
When monitoring is enabled, the service reports statistics including:
Monitor the service health by checking:
ps aux | grep bun
)# Fix file permissions
sudo chown -R www-data:www-data /path/to/wordpress/wp-content/uploads
sudo chmod -R 755 /path/to/wordpress/wp-content/uploads
config.js
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
htop
or similarimages: {
concurrency: Math.min(4, os.cpus().length), // Match CPU cores
quality: {
jpeg: 85, // Balance quality/size
webp: 80, // WebP is more efficient
png: 95, // PNG quality less critical
avif: 70 // AVIF very efficient
}
}
bun run configure # Interactive setup wizard
bun run check # Check system requirements
bun run status # Check service status across all process managers
bun run start # Start the service
bun run dev # Start in development mode with auto-reload
bun test # Run tests
bun run lint # Check code style
Once configured, you can manage the service with:
Supervisor:
sudo supervisorctl start wp-sharp-image
sudo supervisorctl stop wp-sharp-image
sudo supervisorctl restart wp-sharp-image
sudo supervisorctl status wp-sharp-image
systemd:
sudo systemctl start wp-sharp-image
sudo systemctl stop wp-sharp-image
sudo systemctl restart wp-sharp-image
sudo systemctl status wp-sharp-image
PM2:
pm2 start wp-sharp-image
pm2 stop wp-sharp-image
pm2 restart wp-sharp-image
pm2 status wp-sharp-image
pm2 logs wp-sharp-image
bun test
bun run lint
GPL-2.0+ - Same as WordPress
For issues and questions:
Note: This module is designed to replace WordPress's built-in image processing. Ensure you have backups and test thoroughly before deploying to production.
FAQs
High-performance image processing for WordPress using Sharp and Bun
We found that wp-sharp-image demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socketβs new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.