Thumbnail image Generation - Php

Thumbnail Generation

Snippet Code


  
Rate this page :
  [ 0 votes]

This code is about generating thumbnail image

<?php $max_width = 150; $image = imageCreateFromJPEG("sample.jpg"); $current_width = imagesx($image); $current_height = imagesy($image); // Set thumbnail width $widths = array($current_width, $max_width); $new_width = min($widths); // Calculate thumbnail height from given width to maintain ratio $new_height = $current_height / $current_width*$new_width; // Create new image using thumbnail sizes $thumb = imagecreatetruecolor($new_width,$new_height); // Copy original image to thumbnail imagecopyresampled($thumb,$image,0,0,0,0,$new_width,$new_height,imagesx($image),imagesy($image)); // Show thumbnail on screen imagejpeg($thumb, "thumbnail.jpg"); imagedestroy($thumb); ?>

Tags


Ask Questions

Ask Question