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