I have no idea what $Obj_old_image
is or what it is doing based on your posted code. However the following code will work with PHP and the standard GD lib installed:
// image to be scaled
$rawImgPath = './test.jpg';
// new image size (guessing you know the new size)
$newImgSize['w'] = 200;
$newImgSize['h'] = 200;
// the steps to create the new scaled image
$rawImg = imagecreatefromjpeg($rawImgPath);
$newImg = imagecreatetruecolor($newImgSize['w'], $newImgSize['h']);
// need to know the current width and height of the source image
list($rawImgSize['w'], $rawImgSize['h']) = getimagesize($rawImgPath);
// resize the iamge
imagecopyresampled($newImg,$rawImg, 0,0,0,0,
$newImgSize['w'],$newImgSize['h'],$rawImgSize['w'],$rawImgSize['h']);
// no longer need the original
imagedestroy($rawImg);
// display scaled image
header('Content-Type: image/png');
imagepng($newImg);
// no longer need the scaled image
imagedestroy($newImg);
And this code should work and give better results, but does not for me. Basically, imagescale()
is newish code and is not well document on the PHP site.
// image to be scaled
$rawImgPath = './test.jpg';
// new image size (guessing you know the new size)
$newImgSize['w'] = 200;
$newImgSize['h'] = 200;
// the steps to create the new scaled image
$rawImg = imagecreatefromjpeg($rawImgPath);
$newImg = imagescale($rawImg, $newImgSize['w'], $newImgSize['h'],
IMG_BICUBIC_FIXED);
// no longer need the original
imagedestroy($rawImg);
// display scaled image
header('Content-Type: image/png');
imagepng($newImg);
// no longer need the scaled image
imagedestroy($newImg);