I came across few solutions but all those were based on uploading an image. What I want is that it should fetch the image from one folder, resize it of particular size and then save it in other folder.
Asked
Active
Viewed 918 times
0
-
1Instead of asking us to give code, Google it first, then try it, _then_ ask us a constructive question if it doesn't work. – PurkkaKoodari Apr 16 '14 at 06:45
2 Answers
0
Try PHP library function imagecopyresized()
Here is a sample programme,
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// 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);
Here is the manual for imagecopyresized(). http://www.php.net/manual/en/function.imagecopyresized.php

dipak_pusti
- 1,645
- 2
- 23
- 42
-
where should i give the destination path? even it prompts an error on header('Content-Type: image/jpeg'); – sabin Apr 16 '14 at 06:46
-
1If you are copying code from the manual the least you can do is add a reference to it. – AyB Apr 16 '14 at 06:48
-
0
I normally use the GD library for this. It works fine. For an example, please see this url: http://runnable.com/UnF-tFdudNt1AABt/how-to-resize-an-image-using-gd-library-for-php

Rogier Lommers
- 2,263
- 3
- 24
- 38