获取数字值 - 通过PHP创建图像

发布于 2025-01-29 16:13:07 字数 3334 浏览 0 评论 0原文

例如,我与JS进行提取: 根据API开发人员的说法,我本人不需要任何PHP。关于如何制作此工作或信息源的任何信息将不胜感激。 (如果有人知道更好的标题,请告诉我)

71562显示了此图像: akblem

33994显示了此图像: emblem2

因此它们是图案,色彩和徽章叠加的组合。

function test () {
    fetch("https://api.examplesite.com/example/Spoons")
        .then(result => result.json())
        .then ((out) => {
            console.log(out.emblem) // out.emblem returns the numeric value
        })
}

console.log输出:

{name: 'Spoons', realmID: 1, realm: 'Albion', emblem: 71562, realmPoints: 123888, …}
bountyPoints: 5
emblem: 71562 //this is the value needed to somehow create the emblem
members: 17
name: "Spoons"
realm: "Albion"
realmID: 1
realmPoints: 123888

标志号应该代表您可以使用JavaScript(精灵,叠加图像)形成的图片,但不知道如何。

我拥有的此信息是:

标志是叠加模板颜色等 我输出的字符串文本 /公会应该足以构建ID 给定正确的图标文件,请与我一起

这是我从API开发人员那里收到的PHP:

<?php
header ('Content-type: image/png');
$emblem = $_GET['emblem'];
$thumbnail = $_GET['thumbnail'];

$hex = dechex($emblem);
$bin = hexbin($hex);
if ($emblem > 65500)
$logo = substr($bin,-18,-9);
else 
$logo = substr($bin,-16,-9);
$logobin = bindec($logo);
$pattern = substr($bin,-9,-7);
$patternbin = bindec($pattern);
$primary = substr($bin,-7,-3);
$primarybin = bindec($primary);
$secondary = substr($bin,-3,3);
$secondarybin = bindec($secondary);
if($patternbin==3)
{
    $secondarybin = 0;
}
$background = imagecreatefrompng("../images/guildshields/$primarybin-$secondarybin-$patternbin-full.png"); 
$img = imagecreatefromgif("../images/guildshields/Emblems/$logobin.gif");
if ($emblem > 65000)
{
$img2 = imagecreatetruecolor(64, 64);
imagealphablending($img2, false);
imagesavealpha($img2, true);
imageCopyResampled($img2, $img, 0, 0, 0, 0, 64, 64, 128, 128);
}
else 
$img2 = $img;
$img2_width = imagesx($img2);
$img2_height = imagesy($img2);
$bg_width = imagesx($background);
$bg_height = imagesx($background);
imagecopy($background, $img2, ($bg_width-$img2_width)/2, ($bg_height-$img2_height)/2, 0, 0, $img2_width, $img2_height);
if ($thumbnail == "true")
{
    $im = $background;
    $width=ImageSx($im); // Original picture width is stored
    $height=ImageSy($im); // Original picture height is stored
    $thumb=imagecreatetruecolor($width/2,$height/2);
    imageCopyResized($thumb,$im,0,0,0,0,$width/2,$height/2,$width,$height);
    imagepng($thumb);
}
else
{
    imagepng($background); 
}

function hexbin($hex)
{
   $bin='';
   for($i=0;$i<strlen($hex);$i++)
       $bin.=str_pad(decbin(hexdec($hex[$i])),4,'0',STR_PAD_LEFT);
       return $bin;
} 
?>

我从API DEV获得的最后一位信息是:

中输出的字符串

这获取了我从API 。 $ emblem = $ _get ['emblem'];

这是从该字符串中获取的所有信息,徽标将保持在字符串的9-16位置

的位置
$bin = hexbin($hex);
if ($emblem > 65500)
$logo = substr($bin,-18,-9);
else 
$logo = substr($bin,-16,-9);
$logobin = bindec($logo);
$pattern = substr($bin,-9,-7);
$patternbin = bindec($pattern);
$primary = substr($bin,-7,-3);
$primarybin = bindec($primary);
$secondary = substr($bin,-3,3);
$secondarybin = bindec($secondary);

I do a fetch with JS, for example:
According to the API dev, i dont need any PHP myself. Any info on how to make this work, or information sources, would be appreciated.
(if someone knows a better title, let me know)

71562 shows this image:
emblem

33994 shows this image:
emblem2

so they are combinations of a pattern, color and emblem overlay.

function test () {
    fetch("https://api.examplesite.com/example/Spoons")
        .then(result => result.json())
        .then ((out) => {
            console.log(out.emblem) // out.emblem returns the numeric value
        })
}

the console.log outputs:

{name: 'Spoons', realmID: 1, realm: 'Albion', emblem: 71562, realmPoints: 123888, …}
bountyPoints: 5
emblem: 71562 //this is the value needed to somehow create the emblem
members: 17
name: "Spoons"
realm: "Albion"
realmID: 1
realmPoints: 123888

the emblem number should represent a picture that you can form, with javascript (sprites, overlaying images) but no idea how.

this information i have is this:

emblems are made overlaying template colors etc
the string text i output in /guild should be enough to build id
given the correct icon files, bear with me

this is the PHP behind it, that i received from the API developer:

<?php
header ('Content-type: image/png');
$emblem = $_GET['emblem'];
$thumbnail = $_GET['thumbnail'];

$hex = dechex($emblem);
$bin = hexbin($hex);
if ($emblem > 65500)
$logo = substr($bin,-18,-9);
else 
$logo = substr($bin,-16,-9);
$logobin = bindec($logo);
$pattern = substr($bin,-9,-7);
$patternbin = bindec($pattern);
$primary = substr($bin,-7,-3);
$primarybin = bindec($primary);
$secondary = substr($bin,-3,3);
$secondarybin = bindec($secondary);
if($patternbin==3)
{
    $secondarybin = 0;
}
$background = imagecreatefrompng("../images/guildshields/$primarybin-$secondarybin-$patternbin-full.png"); 
$img = imagecreatefromgif("../images/guildshields/Emblems/$logobin.gif");
if ($emblem > 65000)
{
$img2 = imagecreatetruecolor(64, 64);
imagealphablending($img2, false);
imagesavealpha($img2, true);
imageCopyResampled($img2, $img, 0, 0, 0, 0, 64, 64, 128, 128);
}
else 
$img2 = $img;
$img2_width = imagesx($img2);
$img2_height = imagesy($img2);
$bg_width = imagesx($background);
$bg_height = imagesx($background);
imagecopy($background, $img2, ($bg_width-$img2_width)/2, ($bg_height-$img2_height)/2, 0, 0, $img2_width, $img2_height);
if ($thumbnail == "true")
{
    $im = $background;
    $width=ImageSx($im); // Original picture width is stored
    $height=ImageSy($im); // Original picture height is stored
    $thumb=imagecreatetruecolor($width/2,$height/2);
    imageCopyResized($thumb,$im,0,0,0,0,$width/2,$height/2,$width,$height);
    imagepng($thumb);
}
else
{
    imagepng($background); 
}

function hexbin($hex)
{
   $bin='';
   for($i=0;$i<strlen($hex);$i++)
       $bin.=str_pad(decbin(hexdec($hex[$i])),4,'0',STR_PAD_LEFT);
       return $bin;
} 
?>

and last bit of information i got from the API dev is this:

this gets the string i output from the api

$emblem = $_GET['emblem'];

and this is taking all the infos from that string, the logo will be held in the 9-16 position of the string

$bin = hexbin($hex);
if ($emblem > 65500)
$logo = substr($bin,-18,-9);
else 
$logo = substr($bin,-16,-9);
$logobin = bindec($logo);
$pattern = substr($bin,-9,-7);
$patternbin = bindec($pattern);
$primary = substr($bin,-7,-3);
$primarybin = bindec($primary);
$secondary = substr($bin,-3,3);
$secondarybin = bindec($secondary);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文