zoukankan      html  css  js  c++  java
  • PHP图片操作

    <?php
    $filename="http://pic.nipic.com/2007-12-06/2007126102233577_2.jpg";//图片地址
    //获取图片信息
    $info=getimagesize($filename);
    //获取图片类型
    $type=image_type_to_extension($info[2],false);
    //在内存中建立一个和图片类型一样的图像
    $fun="imagecreatefrom{$type}";
    //把图片复制到内存
    $image=$fun($filename);
    //操作图片
    //1、在内存中建立一个宽300高200的真色彩图片
    $image_thumb=imagecreatetruecolor(150, 100);
    //2、将原图复制到新建的真色彩图片上,并且按照一定的比例压缩
    // imagecopyresampled(dst_image, src_image, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
    imagecopyresampled($image_thumb, $image, 0, 0, 0, 0, 150, 100, $info[0], $info[1]);
    //3、销毁原始图片
    imagedestroy($image);
    //把图片输出到浏览器
    header("Content-type:".$info['mime']);
    $funs="image{$type}";
    $funs($image_thumb);
    //保存到硬盘中
    $funs($image_thumb,"thumb_image.".$type);
    imagedestroy($image_thumb);
     ?>
  • 相关阅读:
    图片处理
    define 常量的定义和读取
    curl
    stream_get_contents 和file_get_content的区别
    php flock 文件锁
    字符串函数
    php 常量
    debug_backtrace()
    pathlib模块替代os.path
    Python中对 文件 的各种骚操作
  • 原文地址:https://www.cnblogs.com/mracale/p/5671712.html
Copyright © 2011-2022 走看看