After the script is executed, the generated thumbnail is okay. it is saved normally, but the page shows a small border to solve the problem. thank you!
Watermark = ". /logo.jpg ";} // $ imageInfo is the information returned after the image is uploaded. // $ type-1 indicates the thumbnail of the generated product or article, 2 stands for generating the profile thumbnail public function makeThumb ($ imageInfo, $ with = 360, $ height = 360, $ type = 1) {if ($ imageInfo ['type'] = ". jpg ") {$ src_image = imagecreatefromjpeg ($ imageInfo ['Source _ img_path ']);} else if ($ imageInfo ['type'] = ". png ") {$ src_image = imagecreatefrompng ($ imageInfo ['Source _ img_path ']);} else if ($ imageInfo ['type'] = ". gif ") {$ src_image = Imagecreatefromgif ($ imageInfo ['Source _ img_path ']);} $ image = imagecreatetruecolor ($ with, $ height); $ white = imagecolorallocate ($ image, 255,255,255 ); // set the background to transparent imagecolortransparent ($ image, $ white); imagefill ($ image, $ white); // start to determine the size of the final generated thumbnail, avoid deformation $ finalWidth = $ with; $ finalHeight = $ height; $ x = $ y = 0; if ($ imageInfo ['width'] <$ with & $ imageInfo ['height'] <$ height) {// in this case, do not stretch the source image, place the source image in the middle of the thumbnail $ finalWidth = $ I MageInfo ['width']; $ finalHeight = $ imageInfo ['height']; $ x = round ($ width-$ finalWidth)/2 ); $ y = round ($ height-$ finalHeight)/2);} else if ($ imageInfo ['width']> $ imageInfo ['height']) {// Determine the scaling ratio $ scale = round ($ finalWidth/$ imageInfo ['width'], 2 ); $ finalHeight = round ($ scale * $ imageInfo ['height']); $ y = round ($ height-$ finalHeight)/2 );} else if ($ imageInfo ['width'] <$ imageInfo ['height']) {$ scale = round ($ finalHeight/$ I MageInfo ['height'], 2); $ finalWidth = round ($ scale * $ imageInfo ['height']); $ x = round ($ width-$ finalWidth) /2);} else if ($ imageInfo ['width'] = $ imageInfo ['height']) {if ($ with> $ height) {$ scale = round ($ finalHeight/$ imageInfo ['height'], 2); $ finalWidth = round ($ scale * $ imageInfo ['width']); $ x = round ($ with-$ finalWidth)/2);} else if ($ with <$ height) {$ scale = round ($ finalWidth/$ imageInfo ['width'], 2); $ finalHeight = round ($ Scale * $ imageInfo ['height']); $ y = round ($ height-$ finalHeight)/2) ;}} imagecopyresampled ($ image, $ src_image, $ x, $ y, 0, 0, $ finalWidth, $ finalHeight, $ imageInfo ['width'], $ imageInfo ['height']); // add a watermark if ($ finalWidth >=200 & $ finalHeight >=260) {$ watermark = imagecreatefromjpeg ($ this-> watermark); imagecopymerge ($ image, $ watermark, $ finalWidth-100, $ finalHeight-130, 100,130, 80); imagedestroy ($ watermark );}! Is_dir ($ this-> thumbPath) & mkdir ($ this-> thumbPath); // save path + name $ this-> thumbPath = $ this-> thumbPath. "/". time (). mt_rand (). "_00000000finalwidth0000_00000000finalheight0000.png"; // Finally, the png format is generated in a unified manner, with a high definition header ("content-type: image/png"); imagepng ($ image, $ this-> thumbPath ); imagedestroy ($ image); imagedestroy ($ src_image) ;}} if ($ _ FILES) {$ a = new Thumb (); // the actual image information is the uploaded and processed information. the fixed $ a-> makeThumb (array ('width' => 430, 'height' => 430, 'is written here ,' Type '=> '.jpg', 'source _ img_path '=>'./11.jpg ');}?>
11. jpg
Watermark Image
After the script is executed, the generated thumbnails are OK and saved normally.
But the page shows a small border
Thank you for solving this problem.
Reply content:
Watermark = ". /logo.jpg ";} // $ imageInfo is the information returned after the image is uploaded. // $ type-1 indicates the thumbnail of the generated product or article, 2 stands for generating the profile thumbnail public function makeThumb ($ imageInfo, $ with = 360, $ height = 360, $ type = 1) {if ($ imageInfo ['type'] = ". jpg ") {$ src_image = imagecreatefromjpeg ($ imageInfo ['Source _ img_path ']);} else if ($ imageInfo ['type'] = ". png ") {$ src_image = imagecreatefrompng ($ imageInfo ['Source _ img_path ']);} else if ($ imageInfo ['type'] = ". gif ") {$ src_image = Imagecreatefromgif ($ imageInfo ['Source _ img_path ']);} $ image = imagecreatetruecolor ($ with, $ height); $ white = imagecolorallocate ($ image, 255,255,255 ); // set the background to transparent imagecolortransparent ($ image, $ white); imagefill ($ image, $ white); // start to determine the size of the final generated thumbnail, avoid deformation $ finalWidth = $ with; $ finalHeight = $ height; $ x = $ y = 0; if ($ imageInfo ['width'] <$ with & $ imageInfo ['height'] <$ height) {// in this case, do not stretch the source image, place the source image in the middle of the thumbnail $ finalWidth = $ I MageInfo ['width']; $ finalHeight = $ imageInfo ['height']; $ x = round ($ width-$ finalWidth)/2 ); $ y = round ($ height-$ finalHeight)/2);} else if ($ imageInfo ['width']> $ imageInfo ['height']) {// Determine the scaling ratio $ scale = round ($ finalWidth/$ imageInfo ['width'], 2 ); $ finalHeight = round ($ scale * $ imageInfo ['height']); $ y = round ($ height-$ finalHeight)/2 );} else if ($ imageInfo ['width'] <$ imageInfo ['height']) {$ scale = round ($ finalHeight/$ I MageInfo ['height'], 2); $ finalWidth = round ($ scale * $ imageInfo ['height']); $ x = round ($ width-$ finalWidth) /2);} else if ($ imageInfo ['width'] = $ imageInfo ['height']) {if ($ with> $ height) {$ scale = round ($ finalHeight/$ imageInfo ['height'], 2); $ finalWidth = round ($ scale * $ imageInfo ['width']); $ x = round ($ with-$ finalWidth)/2);} else if ($ with <$ height) {$ scale = round ($ finalWidth/$ imageInfo ['width'], 2); $ finalHeight = round ($ Scale * $ imageInfo ['height']); $ y = round ($ height-$ finalHeight)/2) ;}} imagecopyresampled ($ image, $ src_image, $ x, $ y, 0, 0, $ finalWidth, $ finalHeight, $ imageInfo ['width'], $ imageInfo ['height']); // add a watermark if ($ finalWidth >=200 & $ finalHeight >=260) {$ watermark = imagecreatefromjpeg ($ this-> watermark); imagecopymerge ($ image, $ watermark, $ finalWidth-100, $ finalHeight-130, 100,130, 80); imagedestroy ($ watermark );}! Is_dir ($ this-> thumbPath) & mkdir ($ this-> thumbPath); // save path + name $ this-> thumbPath = $ this-> thumbPath. "/". time (). mt_rand (). "_00000000finalwidth0000_00000000finalheight0000.png"; // Finally, the png format is generated in a unified manner, with a high definition header ("content-type: image/png"); imagepng ($ image, $ this-> thumbPath ); imagedestroy ($ image); imagedestroy ($ src_image) ;}} if ($ _ FILES) {$ a = new Thumb (); // the actual image information is the uploaded and processed information. the fixed $ a-> makeThumb (array ('width' => 430, 'height' => 430, 'is written here ,' Type '=> '.jpg', 'source _ img_path '=>'./11.jpg ');}?>
11. jpg
Watermark Image
After the script is executed, the generated thumbnails are OK and saved normally.
But the page shows a small border
Thank you for solving this problem.
header("content-type:image/png");
Try to delete this paragraph?
You just generate a thumbnail and do not directly display the thumbnail to the browser. However, you have configured the browser output to png format to display a square, that is, the browser wants to display the image, but it does not display the correct image.