图片占位符
本文最后更新于 1460 天前,其中的信息可能已经有所发展或是发生改变。

图片占位符
图片占位符

<?php
// header('Content-type: text/html; charset=UTF-8'); // UTF8不行改成GBK试试,与你保存的格式匹配
 
/**
 * @Author: xiaodongxier
 * @Date:   2020-04-20 09:57:34
 * @Last Modified by:   xiaodongxier
 * @Last Modified time: 2020-04-20 10:17:57
 */

//php动态生成指定大小,指定前景色和背景色的图片

//接收参数
$image_width = isset($_GET['w']) ? intval($_GET['w']) : 750;
$image_height = isset($_GET['h']) ? intval($_GET['h']) : 500;
$image_str = $image_width.'x'.$image_height;
$bc = isset($_GET['bc']) ? hex2rgb($_GET['bc']) : array('r'=>52,'g'=>170,'b'=>220);
$fc = isset($_GET['fc']) ? hex2rgb($_GET['fc']) : array('r'=>255,'g'=>255,'b'=>255);
$num = isset($_GET['n']) ? htmlentities($_GET['n']) : '';

//生成图片
$img = imagecreate($image_width, $image_height);
$backColor = imagecolorallocate($img, $bc['r'], $bc['g'], $bc['b']);
imagefilledrectangle($img, 0, $image_height, $image_width, 0, $backColor);

//插入居中的水印
$fontColor = imagecolorallocate($img, $fc['r'], $fc['g'], $fc['b']);
imagestring($img, 5, $image_width/2-30, $image_height/2-7, $image_str, $fontColor);

//插入居中的水印(小东西儿)
imagestring($img, 5, $image_width/2.5, $image_height/2+10, isset($_GET['f']) ? strrev(strrev($_GET['f'])) : '' , $fontColor);




//插入左下角图片的序号
imagestring($img, 5, $image_width-30, $image_height/10-20, $num, $fontColor);
//插入右下角博客网址(小东西儿)
imagestring($img, 5, $image_width-150, $image_height-30, 'xiaodongxier.com', $fontColor);

//浏览器展示图片
header('Content-type:image/png');
imagepng($img);
imagedestroy($img);


//十六进制颜色转RGB颜色
function hex2rgb($hexColor) {
    $color = str_replace('#', '', $hexColor);
    if (strlen($color) > 3) {
        $rgb = array(
            'r' => hexdec(substr($color, 0, 2)),
            'g' => hexdec(substr($color, 2, 2)),
            'b' => hexdec(substr($color, 4, 2))
        );
    } else {
        $color = $hexColor;
        $r = substr($color, 0, 1) . substr($color, 0, 1);
        $g = substr($color, 1, 1) . substr($color, 1, 1);
        $b = substr($color, 2, 1) . substr($color, 2, 1);
        $rgb = array(
            'r' => hexdec($r),
            'g' => hexdec($g),
            'b' => hexdec($b)
        );
    }
    return $rgb;
}

项目介绍

php仿tempim网页图片占位符

向网页占位符工具 temp.im 致敬

查看了 temp.im 的github,git克隆到本地竟然占用了1.1G 想到php可以用gd库动态生成图片,写了本程序

调用方式

HTTP get

使用说明

get传递参数

名称 必填 说明
w 图片宽度,默认100
h 图片高度,默认100
bc 背景颜色,16进制,默认灰
fc 文字颜色,16进制,默认黑
n 图片编号,数字,默认无
f 图片注释,拼音、数字,默认无

演示地址

http://image.xiaodongxier.com/?w=500&h=300&bc=34AADC&fc=fff&n=1&f=xiaodongxier

标题:图片占位符
地址:https://xiaodongxier.com/72.html
作者:王永杰
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇