Source Code

A Simple PHP Image Resize Code

  • midhun pottmmal
  • 18 November 2013 at 14:01
  • PHP
  • 563
  • 40
  • United States

Author: midhun pottmmal Language: United States
License: Freeware
Size: 0 KB
Downloads: 28 times


PHP image resizing script that will re size JPG and PNG images. Specify a width OR a height OR both. Images are resized proportionally if only a width or a height is specified.

// Get the image info from the photo

= getimagesize($photo); $width = $new_width = $image_info[0]; $height = $new_height = $image_info[1]; $type = $image_info[2]; // Load the image switch ($type) { case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($photo); break; case IMAGETYPE_GIF: $image = imagecreatefromgif($photo); break; case IMAGETYPE_PNG: $image = imagecreatefrompng($photo); break; default: die('Error loading '.$photo.' - File type '.$type.' not supported'); } // Create a new, resized image $new_width = 180; $new_height = $height / ($width / $new_width); $new_image = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Save the new image over the top of the original photo switch ($type) { case IMAGETYPE_JPEG: imagejpeg($image, $photo, 100); break; case IMAGETYPE_GIF: imagegif($image, $photo); break; case IMAGETYPE_PNG: imagepng($image, $photo); break; default: die('Error saving image: '.$photo); }

comments powered by Disqus

Related Code

How Create a Zip File Using PHP

Icon Extractor - full delphi source code

Func-In Delphi Example

Create Search and Get in The Middle String

PHP Script for PING


PHP Sample From CSUSB

Bootstrap UI Kits

Diagram Studio

Simple Graph Component


Tag Linked