แทนที่เราจะใช้การบีบอัดโดยกำหนดความกว้างและสูงของรูปภาพ ลงในส่วนของ
แท็ก <img> วิธีนี้ใช้ได้เหมือนกัน แต่ผลที่ได้คือ ยิ่งเราบีดความกว้างหรือความสูงที่ไม่ใช่ขนาดของไฟล์ภาพต้นฉบับ ความคมชัดและละเอียดของภาพจะยิ่งน้อยลง แต่การโหลดไฟล์ภาพแต่ละครั้งก็ยังเท่าเดิม
ดังนั้น การ Resize จะสร้างรูปภาพมาใหม่ โดยมีความกว้างและความสูงตามที่เรากำหนดใหม่
การ Resize ช่วยลดขนาดปริมาณเนื้อที่ของไฟล์ภาพและการโหลดไฟล์ภาพแต่ละครั้งด้วย
<?php |
ยังมีตัวอย่างอีกเพียบ ทั้ง ทำเป็นฟังก์ชันรับ Resize ภาพได้หลาย นามสกุล และตัวอย่างทำ Thumbnail อีกด้วย
Description
bool imagecopyresampled ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )
" imagecopyresampled() copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity. Returns TRUE on success or FALSE on failure. "
ข้อมูลเพิ่มเติม (http://th2.php.net/manual/en/function.imagecopyresampled.php)