Jump to content

how to resize an image


dearmoawiz

Recommended Posts

you can do a simple resize using html in the image tags

 

<img src="" height=xx width=xx />

 

This is useful for making thumbnails though dependnig on the size of the image, they may take a while to load.  also the width and height you would need to calculate to keep them proportional.

 

If you want to resize an image say for upload, before y ou save it to the server you have to go through a more complex process.  does the simpler method above suffice?  or to you need to resize the image being saved to a server?  what is your situation?

and if you want your own script to handle it:

<?php
/* WARNING: This version only works with JPG files */
$img = //Your image stuff goes here (according to how you are posting the data)
//Percent you want it to resize to
$percent = 0.75;


// Load image
$image = open_image(img);
if ($image === false) { die ('Unable to open image'); }

// Get original width and height
$width = imagesx($image);
$height = imagesy($image);

// New width and height


$new_width = $width * $percent;
$new_height = $height * $percent;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Display resized image
header('Content-type: image/jpeg');
imagejpeg($image_resized);
die();

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.