Based on PHP implementation of compression picture size, _php tutorial

Source: Internet
Author: User
Tags imagejpeg

Based on the PHP implementation, such as compressed image size,


Don't say much nonsense, directly to everyone to paste PHP and other than the size of the compressed image of the relevant code, the specific code is as follows:

<?php$im = Imagecreatefromjpeg (' D:\phpplace\.jpeg '); Resizeimage ($im,,, ' xinde ', '. jpg '); function Resizeimage ($im , $maxwidth, $maxheight, $name, $filetype) {$pic _width = Imagesx ($im); $pic _height = Imagesy ($im); echo " Start-----------------"if ($maxwidth && $pic _width > $maxwidth) && ($maxheight && $pic _ Height > $maxheight) {if ($maxwidth && $pic _width> $maxwidth) {$widthratio = $maxwidth/$pic _width;$ Resizewidth_tag = true;} if ($maxheight && $pic _height> $maxheight) {$heightratio = $maxheight/$pic _height; $resizeheight _tag = true;} if ($resizewidth _tag && $resizeheight _tag) {if ($widthratio < $heightratio) $ratio = $widthratio; else$ratio = $ HeightRatio;} if ($resizewidth _tag &&! $resizeheight _tag) $ratio = $widthratio; if ($resizeheight _tag &&! $resizewidth _tag) $ratio = $heightratio; $newwidth = $pic _width * $ratio; $newheight = $pic _height * $ratio; if (Function_exists (" Imagecopyresampled ") {$newim = Imagecreatetruecolor ($newwidth, $neWheight) imagecopyresampled ($newim, $im,,,,, $newwidth, $newheight, $pic _width, $pic _height);} else{$newim = imagecreate ($newwidth, $newheight); imagecopyresized ($newim, $im,,,,, $newwidth, $newheight, $pic _width, $pic _height);} $name = $name. $filetype; imagejpeg ($newim, $name); Imagedestroy ($newim);}  else{$name = $name. $filetype; imagejpeg ($im, $name);}}

The above code content is small to introduce to you based on the PHP implementation and other than the size of the compressed image of the relevant content, the code is easy to understand, where the bad writing, welcome to all the heroes to put forward valuable comments, small series is very happy.

Articles you may be interested in:

    • PHP thumbnail, such as proportional lossless compression, can fill the blank area supplemental color
    • PHP uses the Imagick module for image scaling, cropping, and compression examples
    • PHP implementation of bulk compressed picture file size Script
    • Two examples of image compression implemented by PHP
    • PHP to add watermark to the image compression cut package class
    • PHP image watermark Add, compress, cut package class implementation
    • PHP implementation image upload and compression
    • How to implement PHP upload image and compress

http://www.bkjia.com/PHPjc/1106112.html www.bkjia.com true http://www.bkjia.com/PHPjc/1106112.html techarticle based on the PHP implementation and other than the compressed image size, no nonsense to say, directly to everyone to paste PHP and other than the compressed image size of the relevant code, the specific code is as follows: Php$im = Imagecreatefr ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.