昨天在qq空间看见一篇“神奇的日志”,不同的访客看到同一张图片会显示对应访客的信息,用chrome 查看了下图片来源是个php文件; 基本原理就是 通过 php文件判断来源页面的url(url中包含qq号码),获取qq号码后通过腾讯的开放api接口,获取qq昵称和qq头像,
昨天在qq空间看见一篇“神奇的日志”,不同的访客看到同一张图片会显示对应访客的信息,用chrome 查看了下图片来源是个php文件;
基本原理就是 通过 php文件判断来源页面的url(url中包含qq号码),获取qq号码后通过腾讯的开放api接口,获取qq昵称和qq头像,然后用gb函数画图,输出
今天试着在网上找到一个文字转图片的程序,改吧改吧写了一个类似的程序,但是写完发了几篇日志才发现腾讯好像已经屏蔽掉外部图片在个人中心中显示了;
把改过的一个 php 文字转图片的类发上来给大家分享下,新手一枚代码改的不是很规整,见谅。。
文件名 Text2Img.class.php
<?php class Text2Img{ //$fontFile = 'msyh.ttc'; #字体文件名,请先拷贝一个字体到font目录下,然后修改此配置 private $LibiFontStyle = "mini.TTF"; private $LibiFontColor = "FF0000"; private $LibiBackColor = "FFFFFF"; private $haveBrLinker = ""; private $LibiWidth; private $Message; function __construct($options=array()){ foreach($options as $key=>$val){ if(!in_array($key,get_class_vars(get_class($this)))){ continue; }else{ $this->$key=$val; } } } private function str_div($str, $width = 10){ $strArr = array(); $len = strlen($str); $count = 0; $flag = 0; while($flag '; if(ord($str[$flag]) > 128){ $count += 1; $flag += 3; } else{ $count += 0.5; $flag += 1 ; } if($count >= $width){ $strArr[] = substr($str, 0, $flag); $str = substr($str, $flag); $len -= $flag; $count = 0; $flag = 0; } } $strArr[] = $str; return $strArr; } private function str2rgb($str) { $color = array('red'=>0, 'green'=>0, 'blue'=>0); $str = str_replace('#', '', $str); $len = strlen($str); if($len==6){ $arr=str_split($str,2); $color['red'] = (int)base_convert($arr[0], 16, 10); $color['green'] = (int)base_convert($arr[1], 16, 10); $color['blue'] = (int)base_convert($arr[2], 16, 10); return $color; } if($len==3){ $arr=str_split($str,1); $color['red'] = (int)base_convert($arr[0].$arr[0], 16, 10); $color['green'] = (int)base_convert($arr[1].$arr[1], 16, 10); $color['blue'] = (int)base_convert($arr[2].$arr[2], 16, 10); return $color; } return $color; } public function text2Img($text){ if($text==''){ $this->Message = "没有文字"; return false; } $text = substr($text, 0, 30000); #截取前一万个字符 $paddingTop = 20; $paddingLeft = 15; $paddingBottom = 20; $copyrightHeight = 36; $canvasWidth = 440; $canvasHeight = $paddingTop + $paddingBottom + $copyrightHeight; $fontSize = 12; $lineHeight = intval($fontSize * 1.8); $textArr = array(); $tempArr = explode("\n", trim($text)); $j = 0; foreach($tempArr as $v){ $arr = $this->str_div($v, 25); $textArr[] = array_shift($arr); foreach($arr as $v){ $textArr[] = $this->haveBrLinker . $v; $j ++; if($j > 100){ break; } } $j ++; if($j > 100){ break; } } $textLen = count($textArr); $canvasHeight = $lineHeight * $textLen + $canvasHeight; $im = imagecreatetruecolor($canvasWidth, $canvasHeight); #定义画布 $colorArray = $this->str2rgb($this->LibiBackColor); imagefill($im, 0, 0, imagecolorallocate($im, $colorArray['red'], $colorArray['green'], $colorArray['blue'])); $colorArray = $this->str2rgb('666666'); $colorLine = imagecolorallocate($im, $colorArray['red'], $colorArray['green'], $colorArray['blue']); $padding = 3; $x1 = $y1 = $x4 = $y2 = $padding; $x2 = $x3 = $canvasWidth - $padding - 1; $y3 = $y4 = $canvasHeight - $padding - 1; imageline($im, $x1, $y1, $x2, $y2, $colorLine); imageline($im, $x2, $y2, $x3, $y3, $colorLine); imageline($im, $x3, $y3, $x4, $y4, $colorLine); imageline($im, $x4, $y4, $x1, $y1, $colorLine); //字体路径 if(!is_file($this->LibiFontStyle)){ $this->Message = "字体文件不存在!"; return false; } //写入四个随即数字 $colorArray = $this->str2rgb($this->LibiFontColor); $fontColor = imagecolorallocate($im, $colorArray['red'], $colorArray['green'], $colorArray['blue']); foreach($textArr as $k=>$text){ $offset = $paddingTop + $lineHeight * ($k + 1) - intval(($lineHeight-$fontSize) / 2); imagettftext($im, $fontSize, 0, $paddingLeft, $offset, $fontColor, $this->LibiFontStyle, $text); } $fontColor = imagecolorallocate($im, 0, 0, 0); $offset += 18; $text = '----END----'; imagettftext($im, 10, 0, $paddingLeft, $offset, $fontColor, $this->LibiFontStyle, $text); $offset += 18; $fontColor = imagecolorallocate($im, 255, 0, 0); $text = 'By Libi'; imagettftext($im, 10, 0, $paddingLeft + 310, $offset, $fontColor, $this->LibiFontStyle, $text); header('Content-Type: image/png'); imagepng($im, $imgfile); imagedestroy($im); } } ?>
原文地址:源码:php文字转图片的类, 感谢原作者分享。

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

Python语言作为一种高级编程语言,具有简单易学、易读易写等特点,在软件开发领域中得到了广泛的应用。然而,由于Python的开源特性,源代码很容易被他人轻易获取,这就给软件源码保护带来了一些挑战。因此,在实际应用中,我们常常需要采取一些方法来保护Python源代码,确保其安全性。在软件源码保护中,有多种针对Python的应用实践可供选择。下面将介绍几种常见

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在php中,可以利用ltrim()函数来去掉字符串首位的tab空白符,语法为“ltrim(string)”;当只给ltrim()函数传入一个参数,用于规定要检查的字符串时,可删除该字符串开始位置的空白字符(例空格、tab制表符、换行符等)。


Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

AI Hentai Generator
Menjana ai hentai secara percuma.

Artikel Panas

Alat panas

ZendStudio 13.5.1 Mac
Persekitaran pembangunan bersepadu PHP yang berkuasa

Pelayar Peperiksaan Selamat
Pelayar Peperiksaan Selamat ialah persekitaran pelayar selamat untuk mengambil peperiksaan dalam talian dengan selamat. Perisian ini menukar mana-mana komputer menjadi stesen kerja yang selamat. Ia mengawal akses kepada mana-mana utiliti dan menghalang pelajar daripada menggunakan sumber yang tidak dibenarkan.

Penyesuai Pelayan SAP NetWeaver untuk Eclipse
Integrasikan Eclipse dengan pelayan aplikasi SAP NetWeaver.

Versi Mac WebStorm
Alat pembangunan JavaScript yang berguna

Muat turun versi mac editor Atom
Editor sumber terbuka yang paling popular