简体   繁体   中英

PHP function works, but the page shows blank

I'm building a photoalbum. You can upload some images, which will be resized, made a record for in the database, etc.. This part works.

Then I wanted to give the photoalbum a thumbnail, to make it look nice in the overview. ( This is the photoalbum-overview ) I think it is more user-friendly to automatically generate a thumbnail from a uploaded file, so I made a function for resizing and cropping the image, but there it goes wrong...

When I proceed to the php-page with the function, I get a blank screen, as if there is something wrong, but there isn't, as the function still cropped and resized the thumbnail image. Also, any other functions called happened to work, but I still get a blank screen.

And when I erase the cropping/resizing function from the file, everything shows up again, so however everything works, this function still appears to be the problem!

This is the function I am talking about: function uploadthumb($path1, $path2, $path3, $path4) {

 $info = getimagesize($path1); $breedte = $info[0]; $hoogte = $info[1]; if($hoogte <= $breedte) { $pseudobreedte = $hoogte*(100/124); $margin1 = ($breedte-$pseudobreedte)/2; $margin2 = $breedte-$pseudobreedte; $img_r = imagecreatefromjpeg($path1); $dst_r = imagecreatetruecolor(100, 124); imagecopyresampled($dst_r,$img_r,0,0,0,0,100,124,$pseudobreedte,$hoogte); //nr. 1 header('Content-type: image/jpeg'); imagejpeg($dst_r,$path2,90); $img_r = imagecreatefromjpeg($path1); $dst_r = imagecreatetruecolor(100, 124); imagecopyresampled($dst_r,$img_r,0,0,$margin1,0,100,124,$pseudobreedte,$hoogte); //nr. 1 header('Content-type: image/jpeg'); imagejpeg($dst_r,$path3,90); $img_r = imagecreatefromjpeg($path1); $dst_r = imagecreatetruecolor(100, 124); imagecopyresampled($dst_r,$img_r,0,0,$margin2,0,100,124,$pseudobreedte,$hoogte); //nr. 1 header('Content-type: image/jpeg'); imagejpeg($dst_r,$path4,90); } else{ $pseudohoogte = $breedte*(124/100); $margin1 = ($hoogte-$pseudohoogte)/2; $margin2 = $hoogte-$pseudohoogte; $img_r = imagecreatefromjpeg($path1); $dst_r = imagecreatetruecolor(100, 124); imagecopyresampled($dst_r,$img_r,0,0,0,0,100,124,$breedte,$pseudohoogte); //nr. 1 header('Content-type: image/jpeg'); imagejpeg($dst_r,$path2,90); $img_r = imagecreatefromjpeg($path1); $dst_r = imagecreatetruecolor(100, 124); imagecopyresampled($dst_r,$img_r,0,0,0,$margin1,100,124,$breedte,$pseudohoogte); //nr. 1 header('Content-type: image/jpeg'); imagejpeg($dst_r,$path3,90); $img_r = imagecreatefromjpeg($path1); $dst_r = imagecreatetruecolor(100, 124); imagecopyresampled($dst_r,$img_r,0,0,0,$margin2,100,124,$breedte,$pseudohoogte); //nr. 1 header('Content-type: image/jpeg'); imagejpeg($dst_r,$path4,90); } } 

The answer for me was pretty simple.. I wanted to save three thumbnails, and the only thing I was doing wrong, was calling the header() function each time. I thought header() specified the image I was saving, but as a matter of fact it specifies the content-type of the document itself, which made the page turn blank.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM