Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To optimize images in PHP, generate derivatives at the dimensions your application actually displays, then re-encode them in a format supported by your deployed PHP/GD build. Check the output’s byte size and appearance on representative images; there is no single quality setting or format that is best for every workload.

Choose an image-optimization workflow

For straightforward resizing, format conversion, and re-encoding, PHP’s GD extension is a practical option. GD can read and write several common image formats, but actual support depends on how PHP and its linked libraries were built. Check the production server rather than assuming a format is available. PHP’s GD installation documentation describes build-dependent support.

  1. Decide the image dimensions your pages or application need. Create derivatives at those dimensions instead of routinely delivering oversized originals.
  2. Inspect the formats supported by the deployed GD library.
  3. Choose an output format based on image content, transparency or animation requirements, deployment support, and delivery needs.
  4. Resize and re-encode, using a controlled quality value where applicable.
  5. Compare dimensions, byte size, and visual appearance against the source using representative files.
  6. Set limits for input dimensions and processing resources. Keep originals if you may need to recover them or generate different derivatives later.

Measure your own image set. Without testing, avoid claiming a particular percentage reduction or a universal quality setting.

Check GD format support on the server

Use gd_info() to inspect build information, or imagetypes() to get a bit-field of image types supported by the GD library linked to PHP. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
<?php
if (!extension_loaded('gd')) {
    throw new RuntimeException('The GD extension is not enabled.');
}

$gd = gd_info();
printf("GD version: %sn", $gd['GD Version'] ?? 'unknown');
printf("WebP support: %sn", !empty($gd['WebP Support']) ? 'yes' : 'no');
printf("AVIF support: %sn", !empty($gd['AVIF Support']) ? 'yes' : 'no');
printf("Supported image type flags: %dn", imagetypes());

Run this against the same PHP runtime and configuration used by the application, not just a developer workstation. The result reflects that GD build and its linked libraries; it does not establish that every source file can be decoded or that every conversion preserves all desired properties. See the imagetypes() manual.

WebP and AVIF build requirements

GD’s WebP build configuration uses --with-webp as of PHP 7.4.0. PHP documents GD AVIF support from PHP 8.1.0 when built with --with-avif. These are build-time conditions: PHP’s version number alone does not prove that the production extension supports the format. Check the installed build before depending on either format. Details are in PHP’s installation documentation.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Resize and re-encode an image with GD

This example reads a JPEG, scales it down so neither dimension exceeds a configured maximum, and writes a WebP derivative. It requires GD with JPEG read and WebP write support. The example assumes a trusted, known input path; it is not a complete upload-validation or security implementation.

<?php
$sourcePath = __DIR__ . '/input.jpg';
$outputPath = __DIR__ . '/output.webp';
$maxWidth = 1600;
$maxHeight = 1600;
$quality = 82;

if (!extension_loaded('gd') || !function_exists('imagewebp')) {
    throw new RuntimeException('GD WebP encoding is not available.');
}

$source = imagecreatefromjpeg($sourcePath);
if ($source === false) {
    throw new RuntimeException('Could not decode the JPEG input.');
}

$width = imagesx($source);
$height = imagesy($source);
$scale = min(1, $maxWidth / $width, $maxHeight / $height);
$newWidth = max(1, (int) round($width * $scale));
$newHeight = max(1, (int) round($height * $scale));

$target = imagecreatetruecolor($newWidth, $newHeight);
if ($target === false) {
    imagedestroy($source);
    throw new RuntimeException('Could not allocate the resized image.');
}

if (!imagecopyresampled(
    $target, $source,
    0, 0, 0, 0,
    $newWidth, $newHeight,
    $width, $height
)) {
    imagedestroy($source);
    imagedestroy($target);
    throw new RuntimeException('Could not resize the image.');
}

$result = imagewebp($target, $outputPath, $quality);
imagedestroy($source);
imagedestroy($target);

if (!$result) {
    throw new RuntimeException('Could not write the WebP output.');
}

printf("Wrote %dx%d; output size: %d bytesn", $newWidth, $newHeight, filesize($outputPath));

The scale factor never enlarges the input: images already within the maximum dimensions retain their dimensions. For production use, also validate that the decoded dimensions are within your application’s limits before allocating a destination image, handle temporary output files and failures safely, and make format selection explicit rather than assuming all uploads are JPEG.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Set quality by testing, not by rule of thumb

imagewebp() accepts a quality argument. PHP’s manual does not designate one universally best value. Compare several settings against the kinds of files your application handles—such as photographs, screenshots, logos, and illustrations—then inspect both the resulting byte sizes and visible artifacts. The imagewebp() manual documents the encoder parameters.

Choose a format and preserve the properties you need

Do not make the decision from file size alone. Consider the image’s content and required properties, then inspect the converted output.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
  • Photographs: compare visual quality and output bytes at the sizes your application serves.
  • Transparent graphics: preserve alpha when needed for logos, overlays, and other graphics. PHP documents imagesavealpha() as meaningful for PNG; WebP and AVIF save the full alpha channel. Verify the output’s appearance and transparency after conversion.
  • Animation: confirm that the chosen processing path retains animation if the application requires it; the GD facts here do not establish preservation for every conversion.
  • Format availability and delivery: confirm server-side read/write support and check client requirements for your application before choosing an output format.

PHP’s explanation of alpha handling is in imagesavealpha(). Format support alone does not guarantee that every source property or visual detail survives re-encoding.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep resource use and untrusted uploads in scope

Large images can require substantial memory while being decoded and resized. PHP’s GD documentation warns that memory allocated by a system GD library may not be governed by PHP’s memory_limit. Account for the deployed library and workload; do not treat that setting as a complete bound on image-processing memory. See the GD installation notes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

For uploads, format conversion is only one part of a safe processing design. Bound input dimensions and processing time, validate files and isolate the processing path appropriately. If using ImageMagick, its security policy can restrict readable and writable formats and set resource limits. Those controls are useful hardening measures, not a complete upload-security design. Consult ImageMagick’s security policy documentation and configure it for the formats and resources your service needs.

Troubleshoot common PHP image-optimization failures

Symptom Likely cause What to check or do
imagewebp() is undefined GD WebP encoding is not enabled in the active PHP build. Check gd_info() and function_exists('imagewebp') in the application’s runtime. Enable or install a GD build with WebP support, or use a supported output format.
Input cannot be decoded The file is corrupt, not the assumed format, or unsupported by the installed GD build. Check the actual file and decoder support. Do not trust a filename extension as proof of content type; handle decode failure before resizing.
Output looks wrong or transparency is missing The output format or conversion path may not retain a required property, or the quality setting may be unsuitable. Inspect representative outputs, confirm alpha requirements, and compare the result at the intended display size. Use a format and encoding path compatible with the image’s needs.
Processing runs out of memory or slows severely Decoded dimensions and intermediate buffers can be much larger than the compressed input file suggests. Reject or route oversized dimensions before processing, create only needed derivatives, and account for system GD library memory separately from PHP’s memory_limit.
AVIF or WebP works locally but not in production The production PHP/GD build or linked libraries differ from local configuration. Run the capability check in production and verify the extension’s build support instead of relying on the PHP version alone.

Or skip the browser setup:

If your task is to capture a webpage as an image or PDF rather than optimize an image file inside PHP, ScreenshotNeo is a website screenshot API with one-request capture. For example, request a screenshot of a page with cURL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. It removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server lets AI agents use screenshot tools. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.