How PHP generates thumbnails

Source: Internet
Author: User
This article mainly introduces how to generate thumbnails in PHP, interested in the reference of friends, I hope to be helpful to everyone.

PHP upload images, generate thumbnails is more commonly used to the function, generally we will write these features a class, convenient for us to call. Today found a simpler PHP generated thumbnail functions of the Code, dare not exclusive, I would like to share with you. Take a careful look at your own use, there are comments in the code.

This article is an example of how PHP simply generates thumbnail albums. Specific as follows:

<?php/* * Written by MOT * root directory own new image thumb directory * */class thumb{private $src;  Private $source;  Private $s _width;  Private $s _height;  Private $dest;  Private $d _height;  Private $d _width;  Private $name;    Public function thumb ($image _path, $rate = 0.5) {$this->src = $image _path;    $this->source = imagecreatefromjpeg ($image _path);    $s _size = getimagesize ($image _path);    $this->s_height = $s _size[1];    $this->s_width = $s _size[0];    $this->d_height = 100;    $this->d_width = 100;    $this->dest = imagecreate ($this->d_width, $this->d_height);    $this->name = explode ('. jpg ', $image _path);  $this->name = $this->name[0]; Public function make () {imagecopyresized ($this->dest, $this->source, 0, 0, 0, 0, $this->d_width, $this-    D_height, $this->s_width, $this->s_height);    $thumb = Str_replace (' image ', ' thumb ', $this->name. '-thumb.jpg ');    Imagejpeg ($this->dest, $thumb, 100);    $img = $thumb; echo "<ahref= $this->src></a> ";  }} $HL = Opendir (". \\image\\"), while (false! = $file = Readdir ($HL)) {if ($file = = '. ' | | $file = = ' ... ') continue;  $path = '. \\image\\ '. $file;  $tmp = new Thumb ($path, 0.3); $tmp->make ();}

Summary: the above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

The method and principle of reversible encryption in PHP

PHP 10 functions for processing sessions

How PHP obtains basic information about users on the public platform

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.