当前位置:网站首页>PHP image upload
PHP image upload
2022-07-28 16:27:00 【Sun Fendou】
Picture upload class
<?php
/** Image compression operation class v1.0 */
class Image{
private $src;
private $imageinfo;
private $image;
public $percent = 0.1;
public function __construct($src=''){
$this->src = $src;
}
/** Open the picture */
public function openImage($src=''){
if (!empty($src)) {
$this->src = $src;
}
list($width, $height, $type, $attr) = getimagesize($this->src);
$this->imageinfo = array(
'width'=>$width,
'height'=>$height,
'type'=>image_type_to_extension($type,false),
'attr'=>$attr
);
$fun = "imagecreatefrom".$this->imageinfo['type'];
$this->image = $fun($this->src);
}
/** Operation picture */
public function thumpImage(){
$new_width = $this->imageinfo['width'] * $this->percent;
$new_height = $this->imageinfo['height'] * $this->percent;
$image_thump = imagecreatetruecolor($new_width,$new_height);
// Copy the original image onto the image carrier , And compressed in proportion , Great clarity
imagecopyresampled($image_thump,$this->image,0,0,0,0,$new_width,$new_height,$this->imageinfo['width'],$this->imageinfo['height']);
imagedestroy($this->image);
$this->image = $image_thump;
}
/** Output pictures */
public function showImage(){
header('Content-Type: image/'.$this->imageinfo['type']);
$funcs = "image".$this->imageinfo['type'];
$funcs($this->image);
}
/** Save pictures to hard disk */
public function saveImage($name){
$funcs = "image".$this->imageinfo['type'];
// $funcs($this->image,$name.'.'.$this->imageinfo['type']);
$funcs($this->image,$name);
}
/** Destroy picture */
public function __destruct(){
imagedestroy($this->image);
}
}
边栏推荐
猜你喜欢

I can only sell the company after the capital has been "cut off" for two years

Common problems and precautions of remote serial port server (adapter) uart/i2c/1-wire/spi PS304

laravel

About standard IO buffers

解决电脑恶意广告弹窗的思路

Zhengda cup hacker marathon data analysis competition

c语言编程当中两个!!的作用

Ethernet to RS485 serial port counter WiFi module LED light controller ibf165

IT远程运维是什么意思?远程运维软件哪个好?

资本「断供」两年,我只能把公司卖了
随机推荐
Sudden! MSI CEO Jiang Shengchang fell to death
Application of optical rain gauge to rainfall detection
KubeEdge发布云原生边缘计算威胁模型及安全防护技术白皮书
SDL2 简明教程(四):用 SDL_IMAGE 库导入图片
PHP mb_substr 中文乱码
Remote serial port server (adapter) UART to 1-wire application
R language ggplot2 visually draws line plots, and uses gghighlight package to highlight the lines that meet the combination judgment conditions in the line graphs (satisfies both condition a and b)
High speed counter to rs485modbus RTU module ibf150
JS stack
Rosen's QT journey 102 listmodel
LwIP development | socket | TCP | client
Fifth uncle's thinking
Detectron2 installation and testing
Roson的Qt之旅#102 ListModel
R language uses ggpairs function of ggally package to visualize pairwise relationship graph of grouping multivariable, set alpha parameter to change image transparency, diagonal continuous variable de
Ask if you don't understand, and quickly become an advanced player of container service!
Ffmpeg get the first frame
Deeply understand the fusing configuration of istio traffic management
ffmpeg获取首帧
The epidemic dividend disappeared, and the "home fitness" foam dissipated