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?

Link to comment
Share on other sites

i need to resize the image being saved on server ... infact the real scenario is that i wanna build a photo album in php so there if i upload images i want that they resized in equal size and then saved on server ... so tht the real scenario did  u got my point???

Link to comment
Share on other sites

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();

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.