国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home 類庫下載 PHP類庫 PHP study notes: Scale images proportionally

PHP study notes: Scale images proportionally

Oct 10, 2016 am 09:55 AM

Go directly to the code. The function imgzip($src,$newwid,$newhei) brings in the original image, the width required for scaling, and the length of scaling. The codes are all noted, if you don’t understand, you can leave a message haha

<?php 

//壓縮圖片  縮略圖

$src= "xiezheng.jpg";
$newwid=640;
$newhei= 480;
function imgzip($src,$newwid,$newhei){
    $imgInfo = getimagesize($src);

    $imgType = image_type_to_extension($imgInfo[2], false);

    $fun = "imagecreatefrom{$imgType}";

//聲明圖片   打開圖片 在內(nèi)存中
    $image = $fun($src);
//方便配置長度寬度、高度,設(shè)置框?yàn)樽兞縲id,高度為hei
    $wid=$imgInfo[0];
    $hei=$imgInfo[1];
//判斷長度和寬度,以方便等比縮放,規(guī)格按照500, 320
    if($wid>$hei){
        $wid=$newwid;
        $hei=$newwid/($wid/$hei);
    }else {
        $wid = $newhei * ($wid / $hei);
        $hei = $newhei;
    }

//在內(nèi)存中建立一張圖片
    $images2 = imagecreatetruecolor($newwid, $newhei); //建立一個(gè)500*320的圖片

//將原圖復(fù)制到新建圖片中
//imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)

    imagecopyresampled($images2, $image, 0, 0, 0, 0, $wid,$hei, $imgInfo[0],$imgInfo[1]);

//銷毀原始圖片
    imagedestroy($image);


//直接輸出圖片文件

    header("Content-type: ".$imgInfo[&#39;mime&#39;]);
    imagejpeg($images2);

//保存圖片 到新文件
    imagejpeg($images2, &#39;new.jpg&#39;, 100); //10代碼輸出圖片的質(zhì)量 0-100 100質(zhì)量最高

//銷毀
    imagedestroy($images2);
}
imgzip($src,$newwid,$newhei);


?>

Effect

Before compression

PHP study notes: Scale images proportionally

After compression

PHP study notes: Scale images proportionally

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
<li id="a4ara"><tbody id="a4ara"></tbody></li>
<label id="a4ara"></label>