PDA

View Full Version : copy image



traiHanoi
18-04-2005, 10:20
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;// 50%
// Content type
header('Content-type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreate($newwidth, $newheight) or die("chua cai thu vien GD");
$source = imagecreatefromjpeg($filename);
//$source=imagetruecolortopalette($source,true,256);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb,"test3.jpg",100);
?>


doan code tren tao ra 1 anh copy test3.jpg co size = 50% anh test.jpg
nhung chat luong anh rat toi.
can bo sung nhu nao de co anh net hon
thks

ohyesssvn
18-04-2005, 16:31
Đổi dòng

$thumb = imagecreate($newwidth, $newheight) or die("chua cai thu vien GD");

thành

$thumb = imagecreatetruecolor($newwidth, $newheight) or die("chua cai thu vien GD");



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

thành

imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

bạn sẽ có chất lượng tốt hơn.