code PHP ทำ thumbnail แบบชัดๆ + ลูกเล่นเพียบ
หลังจากหา codeย่อรูปมานาน
เจอแต่ code ที่ย่อรูปแล้วรูปไม่ชัด
หรือย่อแล้วสัดส่วนผิด
ในที่สุดก็เจอของดี
PHP Thumbnailer Class v2.0 by Gen X Design
วิธีใช้ก็ง่ายๆ เพียงแค่ใส่ include ไฟล์เข้าไป
แล้วก็ new thumbnail เพื่อสร้าง object ของรูปที่เราจะย่อ
<?php
include_once('thumbnail.inc.php');
$thumb = new Thumbnail('path/to/image/file.jpg');
?>
กำหนดขนาดที่ต้องการจะย่อ ใส่ width, height เข้าไป
$thumb->resize($width,$height);
หรือสามารถใส่เป็น % ก็ได้
$thumb->resizePercent(50);
สั่งแสดงรูป
$thumb->show();
หรือสั่ง save
$thumb->save('path/to/file.jpg');
เท่านี้ก็จะได้รูปที่เราย่อแบบสวยงามแล้ว
Crop ภาพ
$thumb->cropFromCenter(100);
หรือทำให้รูปมีเงาสะท้อนก็ใช้คำสั่ง
$thumb->createReflection(40,40,80,true,'#a4a4a4');
คำสั่งอื่นๆ ที่สามารถใช้ได้ดูได้ ที่นี่
หรือ ดาวน์โหลดจากที่นี่
| Print article | This entry was posted by -:- O~o SORA -:- on April 25, 2009 at 1:29 pm, and is filed under Programming. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |






about 1 year ago
Thank you! I would now go on this blog every day!
Pett
about 1 year ago
ขอบคุณมากเลยครับ ใช้งานง่ายดี ขอเก็บไปเล่นนะ อิอิ
about 1 year ago
The best information i have found exactly here. Keep going Thank you
about 1 year ago
Some of us even don’t realize the importance of this information. What a pity.
about 8 months ago
ดาวน์โหลดมาแล้ว ทำยังไงครับ ผมทำแล้ว ภาพขึ้นแต่ไม่เห็นมีอะไรเปลี่ยนแปลงเลยครับ ไม่เหมือนในกระทู้ที่ตั้งไว้เลย ช่วยแนะนำด้วยครับ
about 7 months ago
ลองตรวจสอบดูว่า path ของ include_once(‘thumbnail.inc.php’); ถูกรึเปล่าอ้ะค่ะ