我不知道什麼$Obj_old_image
是或它在做什麼根據您的發佈代碼。不過下面的代碼將使用PHP和安裝標準GD庫工作:
// 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);
而且此代碼應工作,並提供更好的結果,但不適合我。基本上,imagescale()
是PHP網站上的新代碼並且是not well document。
// 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);
可能重複? http://stackoverflow.com/questions/10383305/how-to-resize-an-svg-with-imagick-imagemagick – Mike
沒有它的不重複,忘記SVG 我需要從一個imagick對象加載圖像到另一個更大的尺寸imagick對象。 非常像你從JPEG文件加載圖像到imagick對象,並調整它的大小。 –