80s toys - Atari. I still have

- Nếu tải trang bị lỗi Xt:TimeOut hãy tải lại trang hoặc bấm vàoĐÂY

Admin nhận làm wap,forum giá rẻ. Liên hệ thông tin admin cuối trang để thương lượng giá và demo. Thank all


<?php
class SimpleImage {
var $image;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this ->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this ->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this ->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this ->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg ($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif ($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng ($this->image,$filename);
}
if( $permissions != null) {
chmod ($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg ($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif ($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng ($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this ->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this ->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this ->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled ($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this ->image = $new_image;
}
}
?>
Lưu nội dung trên thành file SimpleImage.php
Cách dùng Class trên: - Ví dụ dưới đây chúng ta sẽ resize ảnh picture.jpg thành kích thước 250x400 sau đó lưu thành file picture2.jpg
<?php
include( 'SimpleImage.php');
$image = new SimpleImage();
$image ->load('picture.jpg');
$image ->resize(250,400);
$image ->save('picture2.jpg');
?>
Nếu bạn muốn resize theo chiều rộng và vẫn giữ đc tỷ lệ giữa chiều rộng và chiêu cao thì tham khảo ví dụ dưới. Ví dụ này sẽ resize chiều rộng file ảnh picture.jpg thành 250 và lưu ra file picture2.jpg
<?php
include( 'SimpleImage.php');
$image = new SimpleImage();
$image ->load('picture.jpg');
$image ->resizeToWidth(250);
$image ->save('picture2.jpg');
?>
Ngoài ra, bạn có thể resize theo tỷ lệ.
Vd sau sẽ resize file ảnh giảm xuống còn 1 nửa (50%)
<?php
include( 'SimpleImage.php');
$image = new SimpleImage();
$image ->load('picture.jpg');
$image ->scale(50);
$image ->save('picture2.jpg');
?>
Bạn có thể resize từ 1 file sau đó xuất ra nhiều file khác nhau. ví dụ sau sẽ resize file picture.jpg có nhiều cao 500px lưu thành file picture2.jpg và chiều cao 200px lưu thành file picture3.jpg
<?php
include( 'SimpleImage.php');
$image = new SimpleImage();
$image ->load('picture.jpg');
$image ->resizeToHeight(500);
$image ->save('picture2.jpg');
$image ->resizeToHeight(200);
$image ->save('picture3.jpg');
?>
Ví dụ sau sẽ xuất thẳng xuống trình duyệt và cho trình duyệt nhận biết đây là ảnh qua header và không cần lưu thành file.
<?php
header ('Content-Type: image/jpeg');
include( 'SimpleImage.php');
$image = new SimpleImage();
$image ->load('picture.jpg');
$image ->resizeToWidth(150);
$image ->output();
?>
Dưới đây là 1 ví dụ cho phép upload 1 ảnh thông qua form rồi resize ảnh thành có chiều rộng 250px rồi xuất ra trình duyệt.(Lưu ý khoảng trắng trước )
<?php
if( isset( $_POST['submit']) ) {
header ('Content-Type: image/jpeg');
include( 'SimpleImage.php');
$image = new SimpleImage();
$image ->load($_FILES['uploaded_image']['tmp_name']);
$image ->resizeToWidth(150);
$image ->output();
exit();
} else {
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploaded_image" />
<input type="submit" name="submit" value="Upload" />
</form>
<?php
}
?>
Nguồn: sinhvienit.net
Tag:
TẮT QCBẬT QC
Liên kết
Wap sex 18+
Thông tin
© Design by: Nhox Attend
© Liên hệ: 01649373906
© Thanks to Xtgem
U-ON
© Filelist Thân Thiện Style VipTruyen