Jump to content

[SOLVED] Resizing a saved image using PHP


waq2062

Recommended Posts

Hi All,

 

I am uploading an image file using move_uploaded_file function. and once the image has been uploaded i want to give user an option to change its height and width so that user could change size of the image and then save it again.

 

Is it possible, can anyone help me out how can i do it.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/135857-solved-resizing-a-saved-image-using-php/
Share on other sites

Heres a basic jpeg resize script.. you should be able to tweak this to suite your needs

 

<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb, $filename);
?>

  • 4 weeks later...

Heres a basic jpeg resize script.. you should be able to tweak this to suite your needs

 

<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb, $filename);
?>

 

Could someone explain me how can i integrate this script into my app. ? I want resizing image jpg file when output only. Size of image remain original but want to make it small when picture requested.

 

Regards

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.