10/10/2018, 10:42
Tạo thumbnail bmp bằng php
Lỗi chạy trên localhost hàm imagecreatefromwbmp và imagewbmp
Warning: imagecreatefromwbmp() [function.imagecreatefromwbmp]: 'images/BLT_untitled.bmp' is not a valid WBMP file in C:AppServwww est aofilehinh.php on line 33
Vậy khắc phục như thế nào?
Các bác hướng dẫn giùm
Thanks
Warning: imagecreatefromwbmp() [function.imagecreatefromwbmp]: 'images/BLT_untitled.bmp' is not a valid WBMP file in C:AppServwww est aofilehinh.php on line 33
Vậy khắc phục như thế nào?
Các bác hướng dẫn giùm
Thanks
Bài liên quan





Nhưng cứ báo lỗi
Nhưng nếu làm cho tất cả các định dạng (jpg, gif, png) thì ok
Còn file bmp thì không được
Hàm này trả về
array(12) { ["GD Version"]=> string(27) "bundled (2.0.34 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["T1Lib Support"]=> bool(true) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XPM Support"]=> bool(false) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) }
Và hiện tại đang lỗi ngay file bmp
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Chức năng tạo ảnh thumbnail: Upload các file ảnh JPG, thay đổi kích thước thực sự (resize) và ghi thành file mới.</title> </head> <body> <form action="" method="post" enctype="multipart/form-data"> <input name="image1" type="file"><br> <input name="image2" type="file"><br> <input name="image3" type="file"><br> <input name="CapNhat" value="Cap Nhat" type="submit"> </form> <?php if($_POST['CapNhat']!="") { $image1 = basename($_FILES['image1']['name']); $image2 = basename($_FILES['image2']['name']); $image3 = basename($_FILES['image3']['name']); $uploaddir = 'images/'; $uploadfile1 = $uploaddir . basename($_FILES['image1']['name']); $uploadfile2 = $uploaddir . basename($_FILES['image2']['name']); $uploadfile3 = $uploaddir . basename($_FILES['image3']['name']); // echo '<pre>'; if (move_uploaded_file($_FILES['image1']['tmp_name'], $uploadfile1)) { echo "Image1 is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; echo "<BR>"; } // echo '<pre>'; if (move_uploaded_file($_FILES['image2']['tmp_name'], $uploadfile2)) { echo "Image2 is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; echo "<BR>"; } // echo '<pre>'; if (move_uploaded_file($_FILES['image3']['tmp_name'], $uploadfile3)) { echo "Image3 is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; echo "<BR>"; } echo "Car inserted into database"; // Now Resize Images /* resizeToFile resizes a picture and writes it to the harddisk * * $sourcefile = the filename of the picture that is going to be resized * $dest_x = X-Size of the target picture in pixels * $dest_y = Y-Size of the target picture in pixels * $targetfile = The name under which the resized picture will be stored * $jpegqual = The Compression-Rate that is to be used */ function resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile,$jpegqual,$type) { /* Get the dimensions of the source picture */ $picsize=getimagesize("$sourcefile"); $source_x = $picsize[0]; $source_y = $picsize[1]; //$source_id = imageCreateFromJPEG("$sourcefile"); switch($type) { case 'jpeg': case 'jpg': case 'JPEG': case 'JPG': $source_id = imageCreateFromJPEG("$sourcefile"); break; case 'gif': case 'GIF': $source_id = imageCreateFromGIF("$sourcefile"); break; case 'png': case 'PNG': $source_id = imageCreateFromPNG("$sourcefile"); break; case 'bmp': case 'BMP': // $source_id = imageCreateFromwBMP("$sourcefile"); $source_id = imagecreatefromwbmp("$sourcefile"); break; } /* Create a new image object (not neccessarily true colour) */ $target_id=imagecreatetruecolor($dest_x, $dest_y); /* Resize the original picture and copy it into the just created image object. Because of the lack of space I had to wrap the parameters to several lines. I recommend putting them in one line in order keep your code clean and readable */ $target_pic=imagecopyresampled($target_id,$source_id, 0,0,0,0, $dest_x,$dest_y, $source_x,$source_y); /* Create a jpeg with the quality of "$jpegqual" out of the image object "$target_pic". This will be saved as $targetfile */ switch($type) { case 'jpeg': case 'jpg': case 'JPEG': case 'JPG': imagejpeg ($target_id,"$targetfile",$jpegqual); break; case 'gif': case 'GIF': imagegif($target_id,"$targetfile",$jpegqual); break; case 'png': case 'PNG': imagepng($target_id,"$targetfile",$jpegqual); break; case 'bmp': case 'BMP': imagewbmp($target_id,"$targetfile",$jpegqual); break; } return true; } //Set Quality to Max $jpegqual = '100'; //Resize Main Image $sourcefile = $uploadfile1; $targetfile = $uploaddir . 'main_' . basename($_FILES['image1']['name']); $dest_x = '570'; $dest_y = '428'; $type_=explode(".",basename($_FILES['image1']['name'])); $type=$type_[count($type_)-1]; resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual,$type); $sourcefile = $uploadfile2; $targetfile = $uploaddir . 'main_' . basename($_FILES['image2']['name']); $dest_x = '570'; $dest_y = '428'; $type_=explode(".",basename($_FILES['image2']['name'])); $type=$type_[count($type_)-1]; resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual,$type); $sourcefile = $uploadfile3; $targetfile = $uploaddir . 'main_' . basename($_FILES['image3']['name']); $dest_x = '570'; $dest_y = '428'; $type_=explode(".",basename($_FILES['image3']['name'])); $type=$type_[count($type_)-1]; resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual,$type); //Create Thumbnails $sourcefile = $uploadfile1; $targetfile = $uploaddir . 'thumb_' . basename($_FILES['image1']['name']); $dest_x = '120'; $dest_y = '90'; $type_=explode(".",basename($_FILES['image1']['name'])); $type=$type_[count($type_)-1]; resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual,$type); $sourcefile = $uploadfile2; $targetfile = $uploaddir . 'thumb_' . basename($_FILES['image2']['name']); $dest_x = '120'; $dest_y = '90'; $type_=explode(".",basename($_FILES['image2']['name'])); $type=$type_[count($type_)-1]; resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual,$type); $sourcefile = $uploadfile3; $targetfile = $uploaddir . 'thumb_' . basename($_FILES['image3']['name']); $dest_x = '120'; $dest_y = '90'; $type_=explode(".",basename($_FILES['image3']['name'])); $type=$type_[count($type_)-1]; resizeToFile ($sourcefile, $dest_x, $dest_y, $targetfile, $jpegqual,$type); //Delete Uploaded Source Files as no longer required if(file_exists($uploadfile1)) unlink($uploadfile1); if(file_exists($uploadfile2)) unlink($uploadfile2); if(file_exists($uploadfile3)) unlink($uploadfile3); } ?> </body> </html>