zoukankan      html  css  js  c++  java
  • 图像处理_03_裁切与缩放

    一  图像裁剪

    <?php
    header('content-type:image/jpeg');//1设置输出图片格式
    
    //2 打开 采样的原图像
    $src_image = imagecreatefromjpeg('ldh.jpg');
    
    //3 创建一个新的 目标图像
    $dst_image = imagecreatetruecolor(500,500);
    
    //4 重点:重采样拷贝部分图像并调整大小
    imagecopyresampled($dst_image,$src_image,100,100,50,200,300,300,300,300);
    
    //5 输出图像
    imagejpeg($dst_image);
    //6 销毁资源
    imagedestroy($dst_image);

    本小节重点:

     imagecopyresampled() 函数

    imagecopyresampled( resource $dst_image, resource $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_w, int $dst_h, int $src_w, int $src_h) : bool
    参数说明:
    dst_image  目标图像资源。
    src_image  源图象资源(你要采样的按个图像资源)
    dst_x dst_y 把采样到的部分,放到目标图像的什么位置
    src_x src_y 你要在源图像哪个坐标开始采样
    dst_w dst_h 放到目标图像资源上面的宽和高
    src_w  src_h 在源图像上采样的宽和高

     

    二  等比例缩放图像

    <?php
    //等比例缩放
    header('content-type:image/jpeg');//1设置输出图片格式
    
    //2 打开 采样的原图像
    $src_image = imagecreatefromjpeg('ldh.jpg');
    $src_width = imagesx($src_image);//取得采样图像的宽度
    $src_height = imagesy($src_image);//取得采样图像的高度
    $equal = $src_width/$src_height;//求出源图像的宽高比 这一步比较重要
    
    //3 创建一个新的 目标图像
    $width = 600;
    $height = $width/$equal;//宽度除以宽高比 求出高度
    $dst_image = imagecreatetruecolor($width,$height);
    
    //4 重点:重采样拷贝部分图像并调整大小
    imagecopyresampled($dst_image,$src_image,0,0,0,0,$width,$height,$src_width,$src_height);
    
    //5 输出图像
    imagejpeg($dst_image);
    //6 销毁资源
    imagedestroy($dst_image);
  • 相关阅读:
    matlab colormap
    张量的基本概念
    河南省测绘资质单位大全
    Meanshift算法
    图形图像的绘制 GandyDraw
    leetcode
    Java 实现装饰(Decorator)模式
    Python
    Asp.Net+Easyui实现重大CRUD
    Scriptcase演示程序,现在,他们使用SC多么简单的开发系统
  • 原文地址:https://www.cnblogs.com/fuyunlin/p/13948765.html
Copyright © 2011-2022 走看看