在WordPress中使用imagejpeg时不起作用

问题描述

美好的一天。为什么当我尝试在外部页面上运行代码时,它运行完美。但是,当我使用wordpress将其添加到页面上时,它给了我一些奇怪的错误。为什么会这样,我该如何解决?

代码:

<?php
// (A) OPEN IMAGE
$img = imagecreatefromjpeg('https://images.unsplash.com/photo-1550684376-efcbd6e3f031?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80');

// (B) WRITE TEXT
$white = imagecolorallocate($img,255,255);
$txt = "sad";
$font = realpath('arial.ttf');
//(IMAGE,FONT SIZE,TILT ANGLE,X,Y,COLOR,FONT,TEXT)
imagettftext($img,12,253,234,$white,$font,$txt);

// (C) OUTPUT IMAGE
header('Content-Type: image/jpeg');
imagejpeg($img);

// OR SAVE TO A FILE
// THE LAST PARAMETER IS THE QUALITY FROM 0 to 100
imagejpeg($img,"test.jpg",100);
?>

这是我在wordpress页面上尝试时得到的结果: Image here

解决方法

问题是您正在以简码运行它,并更改已经创建的输出的标题(即页面)。如果要在站点中显示图像,这取决于您要执行的操作:

AddEventHandler("playerConnecting",function(playerName,setKickReason)
    playerName = string.gsub(playerName,"%W",""):lower()
    for k,v in pairs(unauthNames) do
      local g,f = playerName:find(string.lower(v)
      if g or f then
          print(playerName .. " has been kicked for having an unauthorised name")
          setKickReason("Your name is not permitted. Please check your name is not offensive or associated with blacklisted organisations.")
          CancelEvent()
      end
    end
  end)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...