PHP的图片处理 记录

public function nnn()
{
    $path_1 = '7c54838df41561bb6fdb3f9b55c57964.jpg';   //广告图
    $date = date('Ymd', time());
    $name = uniqid();
    // 图片类型
    $percent='0.8';
    header('Content-Type: image/jpeg');
    // 获得新的图片大小
    list($width, $height) = getimagesize($path_1);
    $new_width = $width * $percent;
    $new_height = $height * $percent;
    // 重新取样
    $image_p = imagecreatetruecolor($new_width, $new_height);
    $path_2 = imagecreatefromjpeg($path_1);
    imagecopyresampled($image_p, $path_2, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    $image = imageCreatetruecolor(900,1600);
    // 为真彩画布创建白色背景
    $color = imagecolorallocate($image, 255, 255, 255);
    imagefill($image, 0, 0, $color);
    // 复制图片一到真彩画布中(重新取样-获取透明图片)
    imagecopyresampled($image, $image_p, 35, 0, 0, 0, imagesx($image_p), imagesy($image_p), imagesx($image_p), imagesy($image_p));
    imagepng($image,'uploads/'.$date.'/'.$name.'.jpg');

    //字体类型,本例为黑体
    $font = __DIR__."/simkai.ttf";
    //显示的文字
    //设置字体颜色
    $black = imagecolorallocatealpha($image, 0, 0, 0,0);
    $str = "山有木兮木有枝";
    //将ttf文字写到图片中
    imagettftext($image, 40, 0, 35, 1250, $black, $font, $str);
    header('content-type:png');
    imagepng($image,'uploads/'.$date.'/'.$name.'.jpg');

    $path_2 = '1a091d7c5a63e74c47a5b0044b953286.jpg';   //二维码图片
    //$path_2图片路径,$percent缩放百分比
    // 图片类型
    $percent='0.4';
    header('Content-Type: image/jpeg');
    // 获得新的图片大小
    list($width, $height) = getimagesize($path_2);
    $new_width = $width * $percent;
    $new_height = $height * $percent;
    // 重新取样
    $image_p = imagecreatetruecolor($new_width, $new_height);
    $path_2 = imagecreatefromjpeg($path_2);
    imagecopyresampled($image_p, $path_2, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    imagecopymerge($image, $image_p, 300, 1300, 0, 0, imagesx($image_p), imagesy($image_p), 100);
    imagepng($image,'public/')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值