PHP Tutorial Create HD Thumbnail details how to use
1. Replace Imagecreate and imagecopyresized with Imagecreatetruecolor and imagecopyresampled functions respectively
2. Take the third parameter to imagejpeg 100 (example: imagejpeg ($ni, $tofile, 100))
Imagecreatetruecolor--Create a new true color image
Description
Resource Imagecreatetruecolor (int x_size, int y_size)
Imagecreatetruecolor () returns an image identifier that represents a black image with a size of x_size and y_size
*/
Header ("Content-type:image/png");
$im = @imagecreatetruecolor (50, 100)
Or Die ("Cannot initialize new GD image stream");
$text _color = imagecolorallocate ($im, 233, 14, 91);
Imagestring ($im, 1, 5, 5, "a simple text string", $text _color);
Imagepng ($im);
Imagedestroy ($im);
/*
If using the normal imagecreate () function will result in distorted picture quality, the solution is searched from the Internet, by replacing the imagecreate () function with the Imagecreateruecolor () function.
*/
function Createpreview ($img, $name, $path, $maxwidth, $maxheight, $quality) {//Picture, save name, save path, maximum width, maximum height, quality
$widthratio = 0;
$heightratio = 0;
$width =imagesx ($IMG);
$height =imagesy ($IMG);
Start calculating the scale-down
if ($width > $maxwidth | | $height > $maxheight) {
if ($width > $maxwidth) {
$widthratio = $maxwidth/$width;
}
if ($height > $maxheight) {
$heightratio = $maxheight/$height;
}
if ($widthratio >0&& $heightratio >0) {
if ($widthratio < $heightratio) {
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif ($widthratio >0) {
$ratio = $widthratio;
}elseif ($heightratio >0) {
$ratio = $heightratio;
}
Recalculate the width and height of thumbnails based on the resulting proportions
$newwidth = $ratio * $width;
$newheight = $ratio * $height;
$newimg =imagecreatetruecolor ($newwidth, $newheight); Create a target diagram
Imagecopyresized ($newimg, $img, 0,0,0,0, $newwidth, $newheight, $width, $height);
Imagejpeg ($newimg, $path. " S_ ". $name, $quality);
Imagedestroy ($NEWIMG);
}else{
Imagejpeg ($img, $path. " S_ ". $name, $quality);
}
}
/*
Imagecopyresamples (), the pixel interpolation algorithm gets a smoother image edge. Good quality (but the function is slower than imagecopyresized ().)
http://www.bkjia.com/PHPjc/633003.html www.bkjia.com true http://www.bkjia.com/PHPjc/633003.html techarticle PHP Tutorial Create HD Thumbnail details using Method 1. Replace Imagecreate and imagecopyresized 2 with the Imagecreatetruecolor and imagecopyresampled functions respectively. Give imagejpeg a third parameter ...