PHP的图片处理 记录

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u013032345/article/details/82757467
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/')
展开阅读全文

没有更多推荐了,返回首页