• 一次生成多种不同尺寸的缩略图


    
    <?php
    
    $filename="1.png";
    
    list($src_w,$src_h,$imagetype)=getimagesize($filename);
    $mime=image_type_to_mime_type($imagetype);
    //echo $mime;
    $createfun=str_replace("/","createfrom",$mime);
    $outfun=str_replace("/",null,$mime);
    $src_image=$createfun($filename);
    
    $dst_50_image=imagecreatetruecolor(50,50);
    $dst_222_image=imagecreatetruecolor(222,222);
    $dst_350_image=imagecreatetruecolor(350,350);
    $dst_800_image=imagecreatetruecolor(800,800);
    
    imagecopyresampled($dst_50_image, $src_image, 0, 0, 0, 0,50, 50, $src_w, $src_h);
    imagecopyresampled($dst_222_image, $src_image, 0, 0, 0, 0,222, 222, $src_w, $src_h);
    imagecopyresampled($dst_350_image, $src_image, 0, 0, 0, 0,350,350, $src_w, $src_h);
    imagecopyresampled($dst_800_image, $src_image, 0, 0, 0, 0,800, 800, $src_w, $src_h);
    
    $outfun($dst_50_image,'uploads/images_50/'.$filename);
    $outfun($dst_222_image,'uploads/images_222/'.$filename);
    $outfun($dst_350_image,'uploads/images_350/'.$filename);
    $outfun($dst_800_image,'uploads/images_800/'.$filename);
    
    imagedestroy($src_image);
    imagedestroy($dst_50_image);
    imagedestroy($dst_222_image);
    imagedestroy($dst_350_image);
    imagedestroy($dst_800_image);
    
    ?>
    
    
  • 相关阅读:
    PHP -----上传文件
    PHP----预定义数组
    PHP-------- 会话控制
    PHP------XML
    PHP----练习-----三级联动
    PHP-------ajax返回值 返回JSON 数据
    PHP----练习----光标离开文本框时变色
    使用ansible安装配置zabbix客户端
    svn+apache安装配置
    rsync+lsyncd实现实时同步
  • 原文地址:https://www.cnblogs.com/datiangou/p/10199971.html
Copyright © 2020-2023  润新知