หากต้องการส่งคืนส่วนใดขององค์ประกอบตำแหน่งที่มองเห็นได้ ให้ใช้คลิป คุณสมบัติใน JavaScript
ตัวอย่าง
คุณสามารถลองใช้โค้ดต่อไปนี้เพื่อเรียนรู้วิธีตัดรูปภาพ -
<!DOCTYPE html>
<html>
<head>
<style>
img {
position: absolute;
top: 100px;
}
</style>
</head>
<body>
<button type="button" onclick="display()">Clip</button><br>
<img id="newImg" src="https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg" width="170" height="150">
<script>
function display() {
document.getElementById("newImg").style.clip = "rect(10px 90px 90px 10px)";
}
</script>
</body>
</html>