Image Thumbnails Generation Implementation for Website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Showing 1 of 1 servicesAll 2065 services
Image Thumbnails Generation Implementation for Website
Medium
~2-3 business days
FAQ
Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Image Thumbnails Generation

Thumbnail generation transforms uploaded images into multiple sizes for different contexts (list, card, full-size view) without losing original.

Laravel: Intervention Image + queue

// Model with automatic thumbnail generation
class Image extends Model
{
    const SIZES = [
        'thumb'  => [200, 200],
        'medium' => [600, 400],
        'large'  => [1200, 800],
    ];
}

// Job for async generation
class GenerateImageThumbnails implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;

    public function __construct(private Image $image) {}

    public function handle(): void
    {
        $originalPath = Storage::disk('s3')->path($this->image->path);
        $img = \Intervention\Image\Facades\Image::make($originalPath);

        foreach (Image::SIZES as $size => [$width, $height]) {
            $resized = clone $img;
            $resized->fit($width, $height);  // crop to center

            $thumbPath = str_replace('original/', "{$size}/", $this->image->path);
            Storage::disk('s3')->put($thumbPath, $resized->encode('webp', 85)->__toString());
        }

        $this->image->update(['processed' => true]);
    }
}

// Upload controller
public function store(Request $request): JsonResponse
{
    $path = Storage::disk('s3')->putFile('original', $request->file('image'));

    $image = Image::create([
        'path'       => $path,
        'user_id'    => auth()->id(),
        'processed'  => false,
    ]);

    GenerateImageThumbnails::dispatch($image);

    return response()->json(['id' => $image->id]);
}

Node.js: Sharp

Sharp is the fastest Node.js image processing library (based on libvips).

import sharp from 'sharp';
import { S3Client, GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';

const SIZES = {
  thumb:  { width: 200, height: 200 },
  medium: { width: 600, height: 400 },
  large:  { width: 1200, height: 800 },
} as const;

async function generateThumbnails(s3Key: string): Promise<Record<string, string>> {
  const s3 = new S3Client({ region: 'eu-west-1' });

  // Download original
  const { Body } = await s3.send(new GetObjectCommand({
    Bucket: process.env.S3_BUCKET!,
    Key: s3Key,
  }));

  const buffer = Buffer.from(await (Body as any).transformToByteArray());

  const results: Record<string, string> = {};

  await Promise.all(
    Object.entries(SIZES).map(async ([name, { width, height }]) => {
      const thumbnail = await sharp(buffer)
        .resize(width, height, { fit: 'cover', position: 'centre' })
        .webp({ quality: 85 })
        .toBuffer();

      const thumbKey = s3Key.replace('original/', `${name}/`).replace(/\.[^.]+$/, '.webp');

      await s3.send(new PutObjectCommand({
        Bucket: process.env.S3_BUCKET!,
        Key: thumbKey,
        Body: thumbnail,
        ContentType: 'image/webp',
        CacheControl: 'public, max-age=31536000',
      }));

      results[name] = thumbKey;
    })
  );

  return results;
}

Lazy generation via Glide (PHP)

Glide generates thumbnails on demand with signed URLs:

// Image route
Route::get('/img/{path}', function (Request $request, string $path) {
    $server = League\Glide\ServerFactory::create([
        'source'    => Storage::disk('s3')->getDriver(),
        'cache'     => Storage::disk('local')->getDriver(),
        'cache_path_prefix' => '.cache',
        'base_url'  => '/img',
        'max_image_size' => 2000 * 2000,
    ]);

    // Validate signed URL
    League\Glide\Signatures\SignatureFactory::create(config('app.key'))
        ->validateRequest('/img/' . $path, $request->all());

    return $server->getImageResponse($path, $request->all());
})->where('path', '.*');

// Generate signed URL
$url = (new League\Glide\Urls\UrlBuilderFactory)
    ->create('/img', config('app.key'))
    ->getUrl('uploads/photo.jpg', ['w' => 400, 'h' => 300, 'fit' => 'crop']);

Formats and optimization

// Choose format by browser support
const output = sharp(buffer)
  .resize(800)
  .toFormat(supportsAvif ? 'avif' : supportsWebp ? 'webp' : 'jpeg', {
    quality: supportsAvif ? 60 : supportsWebp ? 80 : 85,
  });

AVIF gives 50% savings compared to JPEG at same quality. WebP is supported by all modern browsers. For maximum compatibility use <picture> with multiple formats.

Implementation timeline

Thumbnail generation in queue (Laravel Job or BullMQ Worker) with S3 storage: 2–3 days. With lazy generation via Glide and CDN caching: 3–4 days.