<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>dwt&#039;s life - PHP</title>
<link>https://dwt.life/tag/PHP/</link>
<atom:link href="https://dwt.life/feed/tag/PHP/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description></description>
<lastBuildDate>Sat, 21 Jan 2023 20:45:11 +0800</lastBuildDate>
<pubDate>Sat, 21 Jan 2023 20:45:11 +0800</pubDate>
<item>
<title>PHP去除LR LF等特殊字符串</title>
<link>https://dwt.life/archives/320/</link>
<guid>https://dwt.life/archives/320/</guid>
<pubDate>Sat, 21 Jan 2023 20:45:11 +0800</pubDate>
<dc:creator>Ricky</dc:creator>
<description><![CDATA[function clean($text){    return trim(preg_replace(&quot;/(\s*[\r\n]+\s*|\s+)/&quot;, &#039; &#03...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<pre><code class="lang-php">function clean($text)
{
    return trim(preg_replace(&quot;/(\s*[\r\n]+\s*|\s+)/&quot;, &#039; &#039;, $text));
}</code></pre><blockquote>the first part \s<em>[\r\n]+\s</em> will replace any line breaks, it's leading spaces and it's tailing spaces into just one space.<br>the second part \s+ will shrink spaces into one space.<br>then trim() removes the leading/tailing space.</blockquote>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://dwt.life/archives/320/#comments</comments>
<wfw:commentRss>https://dwt.life/feed/tag/PHP/</wfw:commentRss>
</item>
<item>
<title>PHP ssh</title>
<link>https://dwt.life/archives/311/</link>
<guid>https://dwt.life/archives/311/</guid>
<pubDate>Mon, 12 Sep 2022 17:15:08 +0800</pubDate>
<dc:creator>Ricky</dc:creator>
<description><![CDATA[&lt;?phpclass NiceSSH {    // SSH Host    private $ssh_host = &#039;myserver.example.com&#039;;  ...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<pre><code class="lang-php">&lt;?php
class NiceSSH {
    // SSH Host
    private $ssh_host = &#039;myserver.example.com&#039;;
    // SSH Port
    private $ssh_port = 22;
    // SSH Server Fingerprint
    private $ssh_server_fp = &#039;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&#039;;
    // SSH Username
    private $ssh_auth_user = &#039;username&#039;;
    // SSH Public Key File
    private $ssh_auth_pub = &#039;/home/username/.ssh/id_rsa.pub&#039;;
    // SSH Private Key File
    private $ssh_auth_priv = &#039;/home/username/.ssh/id_rsa&#039;;
    // SSH Private Key Passphrase (null == no passphrase)
    private $ssh_auth_pass;
    // SSH Connection
    private $connection;
   
    public function connect() {
        if (!($this-&gt;connection = ssh2_connect($this-&gt;ssh_host, $this-&gt;ssh_port))) {
            throw new Exception(&#039;Cannot connect to server&#039;);
        }
        $fingerprint = ssh2_fingerprint($this-&gt;connection, SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX);
        if (strcmp($this-&gt;ssh_server_fp, $fingerprint) !== 0) {
            throw new Exception(&#039;Unable to verify server identity!&#039;);
        }
        if (!ssh2_auth_pubkey_file($this-&gt;connection, $this-&gt;ssh_auth_user, $this-&gt;ssh_auth_pub, $this-&gt;ssh_auth_priv, $this-&gt;ssh_auth_pass)) {
            throw new Exception(&#039;Autentication rejected by server&#039;);
        }
    }
    public function exec($cmd) {
        if (!($stream = ssh2_exec($this-&gt;connection, $cmd))) {
            throw new Exception(&#039;SSH command failed&#039;);
        }
        stream_set_blocking($stream, true);
        $data = &quot;&quot;;
        while ($buf = fread($stream, 4096)) {
            $data .= $buf;
        }
        fclose($stream);
        return $data;
    }
    public function disconnect() {
        $this-&gt;exec(&#039;echo &quot;EXITING&quot; &amp;&amp; exit;&#039;);
        $this-&gt;connection = null;
    }
    public function __destruct() {
        $this-&gt;disconnect();
    }
}
?&gt;</code></pre>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://dwt.life/archives/311/#comments</comments>
<wfw:commentRss>https://dwt.life/feed/tag/PHP/</wfw:commentRss>
</item>
<item>
<title>PHP异常处理之获取错误发生的所在行</title>
<link>https://dwt.life/archives/203/</link>
<guid>https://dwt.life/archives/203/</guid>
<pubDate>Sun, 24 Apr 2022 21:35:08 +0800</pubDate>
<dc:creator>Ricky</dc:creator>
<description><![CDATA[在异常被捕获之后，我们可以通过异常处理对象获取其中的异常信息。在实际应用中，我们通常会获取足够多的异常信息，然后写入到错误日志中。通常我们需要将报错的文件名、行号、错误信息、导演追踪信息等记录到...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>在异常被捕获之后，我们可以通过异常处理对象获取其中的异常信息。</p><p>在实际应用中，我们通常会获取足够多的异常信息，然后写入到错误日志中。</p><p>通常我们需要将报错的文件名、行号、错误信息、导演追踪信息等记录到日志中，以便调试与修复问题。</p><pre><code class="lang-php">&lt;?php
 
try {
    throw new Exception(&#039;错误信息&#039;);
} cathc (Exception $e) {
    $msg = &#039;Error: &#039; . $e-&gt;getMessage(); // 获取错误信息
    
    $msg .= $e-&gt;getTraceAsString(); // 获取字符串类型的异常追踪信息
    
    $msg .= &#039;异常行号：&#039; . $e-&gt;getLine(); // 异常发生所在行
    
    $msg .= &#039;所在文件：&#039; . $e-&gt;getFile(); // 异常发生所在文件绝对路径
    
    file_put_contents(&#039;error.log&#039;, $msg);
}</code></pre>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://dwt.life/archives/203/#comments</comments>
<wfw:commentRss>https://dwt.life/feed/tag/PHP/</wfw:commentRss>
</item>
<item>
<title>Nmap web在线精确扫描、检测服务器端口开放</title>
<link>https://dwt.life/archives/192/</link>
<guid>https://dwt.life/archives/192/</guid>
<pubDate>Thu, 17 Feb 2022 00:19:00 +0800</pubDate>
<dc:creator>Ricky</dc:creator>
<description><![CDATA[composer安装项目目录执行composer require palepurple/nmap修改代码原来的composer src中的代码并不会进行精确扫描，需要修改文件vendor/pal...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<h2>composer安装</h2><p>项目目录执行<code>composer require palepurple/nmap</code></p><h2>修改代码</h2><p>原来的composer src中的代码并不会进行精确扫描，需要修改文件<code>vendor/palepurple/nmap/src/Nmap/Nmap.php</code>代码实现该功能：</p><pre><code class="lang-php">    private $enableTcp = false;

    public function buildCommand(array $targets, array $ports = array()): array
    {

        if (true === $this-&gt;enableTcp) {
            $options[] = &#039;-sT&#039;;
        }
    }

    public function enableTcp($enable = true): self
    {
        $this-&gt;enableTcp = $enable;

        return $this;
    }</code></pre><h2>注</h2><p>针对Centos，可以使用<code>yum install nmap</code>进行安装，否则将无法运行扫描。<br>另外需要开放<code>exec</code>函数的执行权限。<br>最后如果要对接web，可以使用workerman websocket连接实现逐行显示。<br>可以见我实现的功能：<a href="https://tool.hi.cn/port/">端口开放在线检测工具</a></p><p><a href="https://tool.hi.cn/port/">https://tool.hi.cn/port/</a></p>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://dwt.life/archives/192/#comments</comments>
<wfw:commentRss>https://dwt.life/feed/tag/PHP/</wfw:commentRss>
</item>
<item>
<title>ThinkPHP5中如何加入插件功能</title>
<link>https://dwt.life/archives/188/</link>
<guid>https://dwt.life/archives/188/</guid>
<pubDate>Mon, 31 Jan 2022 17:28:00 +0800</pubDate>
<dc:creator>Ricky</dc:creator>
<description><![CDATA[加入插件的方法：1、在系统的index.php入口中加入如下配置// 插件目录define(&#039;ADDON_PATH&#039;, __DIR__ . &#039;/../addons/...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>加入插件的方法：</p><p>1、在系统的index.php入口中加入如下配置</p><pre><code class="lang-php">// 插件目录
define(&#039;ADDON_PATH&#039;, __DIR__ . &#039;/../addons/&#039;);
// 开启系统行为
define(&#039;APP_HOOK&#039;, true);</code></pre><p>2、在数据库中加入addons插件表和hooks钩子表</p><pre><code class="lang-sql">CREATE TABLE `addons` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT &#039;主键&#039;,
  `name` varchar(40) NOT NULL COMMENT &#039;插件名或标识&#039;,
  `title` varchar(20) NOT NULL DEFAULT &#039;&#039; COMMENT &#039;中文名&#039;,
  `description` text COMMENT &#039;插件描述&#039;,
  `status` tinyint(1) NOT NULL DEFAULT &#039;1&#039; COMMENT &#039;状态&#039;,
  `config` text COMMENT &#039;配置&#039;,
  `author` varchar(40) DEFAULT &#039;&#039; COMMENT &#039;作者&#039;,
  `version` varchar(20) DEFAULT &#039;&#039; COMMENT &#039;版本号&#039;,
  `create_time` int(10) unsigned NOT NULL DEFAULT &#039;0&#039; COMMENT &#039;安装时间&#039;,
  `has_adminlist` tinyint(1) unsigned NOT NULL DEFAULT &#039;0&#039; COMMENT &#039;是否有后台列表&#039;,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT=&#039;插件表&#039;;

CREATE TABLE `hooks` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT &#039;主键&#039;,
  `name` varchar(40) NOT NULL DEFAULT &#039;&#039; COMMENT &#039;钩子名称&#039;,
  `description` text NOT NULL COMMENT &#039;描述&#039;,
  `type` tinyint(1) unsigned NOT NULL DEFAULT &#039;1&#039; COMMENT &#039;类型&#039;,
  `update_time` int(10) unsigned NOT NULL DEFAULT &#039;0&#039; COMMENT &#039;更新时间&#039;,
  `addons` varchar(255) NOT NULL DEFAULT &#039;&#039; COMMENT &#039;钩子挂载的插件 &#039;&#039;，&#039;&#039;分割&#039;,
  `status` tinyint(2) DEFAULT &#039;1&#039;,
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;</code></pre><p>3、在ThinkPHP5的根目录中创建addons目录</p><pre><code>www  WEB项目目录
├─composer.json         composer定义文件
├─README.md             README文件
├─LICENSE.txt           授权说明文件
├─addons                插件目录（新增）
├─application           应用目录
│  ├─common             公共模块目录（可以更改）
│  ├─runtime            应用的运行时目录（可写，可定制）
│  ├─module             模块目录
│  │  └─ ...            更多类库目录
│  ├─common.php         公共函数文件
│  ├─config.php         公共配置文件
│  ├─route.php          路由配置文件
│  └─database.php       数据库配置文件
│
├─public                WEB目录（对外访问目录）
│  ├─index.php          入口文件
│  ├─.htaccess          用于apache的重写
│  └─router.php         快速测试文件（用于PHP内置webserver）
│
├─thinkphp              框架系统目录</code></pre><p>4、在application中的common.php公共函数里添加两个公共方法</p><pre><code class="lang-php">/**
 * 获取插件类的类名
 * @param strng $name 插件名
 * @param string $ext 扩展名
 */
function get_addon_class($name, $ext = EXT)
{
    // 初始化命名空间及类名
    $class = &quot;addons\\{$name}\\&quot; . ucfirst($name);
    return $class;
}

/**
 * 处理插件钩子
 * @param string $hook   钩子名称
 * @param mixed $params 传入参数
 * @return void
 */
function hook($hook, $params = [])
{
    // 钩子调用
    \think\Hook::listen($hook, $params);
}</code></pre><p>5、在application目录下创建common模块，在common模块中创建behavior行为目录，在公共行为目录中创建Hooks.php钩子行为插件，内容如下：</p><pre><code class="lang-php">&lt;?php
// +----------------------------------------------------------------------
// | zzstudio [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.zzstudio.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Byron Sampson &lt;xiaobo.sun@gzzstudio.net&gt;
// +----------------------------------------------------------------------
namespace app\common\behavior;

use think\Hook;

class Hooks
{
    public function run(&amp;$param = [])
    {
        if(defined(&#039;BIND_MODULE&#039;) &amp;&amp; BIND_MODULE === &#039;Install&#039;) return;
        // 动态加入命名空间
        \think\Loader::addNamespace(&#039;addons&#039;, ADDON_PATH);
        // 获取钩子数据
        $data = S(&#039;hooks&#039;);
        if(!$data){
            $hooks = M(&#039;Hooks&#039;)-&gt;getField(&#039;name,addons&#039;);
            // 获取钩子的实现插件信息
            foreach ($hooks as $key =&gt; $value) {
                if($value){
                    $map[&#039;status&#039;]  =   1;
                    $names          =   explode(&#039;,&#039;,$value);
                    $map[&#039;name&#039;]    =   [&#039;IN&#039;, $names];
                    $data = M(&#039;Addons&#039;)-&gt;where($map)-&gt;getField(&#039;id,name&#039;);
                    if($data){
                        $addons = array_intersect($names, $data);
                        Hook::add($key, array_map(&#039;get_addon_class&#039;, $addons));
                    }
                }
            }
            S(&#039;hooks&#039;, Hook::get());
        }else{
            Hook::import($data, false);
        }
    }
}</code></pre><p>6、在application目录中创建tags.php行为配置文件，并且加入内容</p><pre><code class="lang-php">&lt;?php
// 系统行为定义
return [
    &#039;app_init&#039; =&gt; [
        &#039;app\\common\\behavior\\Hooks&#039;
    ],
    &#039;action_begin&#039;=&gt; [
    ],
    &#039;app_end&#039;=&gt; [
    ]
];</code></pre><p>到此为止，插件功能就集成完毕了。</p><p>接下来我们做个简单的插件试一下：</p><p>1、在addons目录中创建一个Base.php 插件的基类</p><pre><code class="lang-php">&lt;?php
// +----------------------------------------------------------------------
// | addons [ WE CAN DO IT JUST ZZSTUDIO IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015 http://www.zzstudio.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: byron sampson &lt;xiaobo.sun@zzstudio.net&gt;
// +----------------------------------------------------------------------
namespace addons;

/**
 * 插件类
 * @author byron sampson &lt;xiaobo.sun@zzstudio.net&gt;
 */
abstract class Base{
    /**
     * 视图实例对象
     * @var view
     * @access protected
     */
    protected $view = null;

    /**
     * $info = array(
     *  &#039;name&#039;=&gt;&#039;Editor&#039;,
     *  &#039;title&#039;=&gt;&#039;编辑器&#039;,
     *  &#039;description&#039;=&gt;&#039;用于增强整站长文本的输入和显示&#039;,
     *  &#039;status&#039;=&gt;1,
     *  &#039;author&#039;=&gt;&#039;thinkphp&#039;,
     *  &#039;version&#039;=&gt;&#039;0.1&#039;
     *  )
     */
    public $info                =   array();
    public $addon_path          =   &#039;&#039;;
    public $config_file         =   &#039;&#039;;
    public $custom_config       =   &#039;&#039;;
    public $admin_list          =   array();
    public $custom_adminlist    =   &#039;&#039;;
    public $access_url          =   array();

    /**
     * 基类构造函数
     * Base constructor.
     */
    public function __construct()
    {
        $this-&gt;view         =   new \think\View();
        $this-&gt;addon_path   =   ADDON_PATH . $this-&gt;getName() . &#039;/&#039;;
        $TMPL_PARSE_STRING = C(&#039;parse_str&#039;);
        $TMPL_PARSE_STRING[&#039;__ADDONROOT__&#039;] = $TMPL_PARSE_STRING[&#039;__ADDONS__&#039;] . &#039;/&#039; . $this-&gt;getName();
        C(&#039;parse_str&#039;, $TMPL_PARSE_STRING);
        if(is_file($this-&gt;addon_path . &#039;config.php&#039;)){
            $this-&gt;config_file = $this-&gt;addon_path . &#039;config.php&#039;;
        }
    }

    /**
     * 模板主题设置
     * @access protected
     * @param string $theme 模版主题
     * @return Action
     */
    final protected function theme($theme)
    {
        $this-&gt;view-&gt;theme($theme);
        return $this;
    }

    /**
     * 模板变量赋值
     * @access protected
     * @param mixed $name 要显示的模板变量
     * @param mixed $value 变量的值
     * @return Action
     */
    final protected function assign($name, $value=&#039;&#039;)
    {
        $this-&gt;view-&gt;assign($name,$value);
        return $this;
    }


    //用于显示模板的方法
    final protected function fetch($templateFile = CONTROLLER_NAME)
    {
        if(!is_file($templateFile)){
            $templateFile = $this-&gt;addon_path . $templateFile . &quot;.html&quot;;
            if(!is_file($templateFile)){
                E(L(&#039;_TEMPLATE_NOT_EXIST_&#039;) . &quot;:$templateFile&quot;);
            }
        }
        return $this-&gt;view-&gt;fetch($templateFile);
    }

    /**
     * 获取插件名
     * @return string
     */
    final public function getName()
    {
        $class = get_class($this);
        list($space, $name, $class) = explode(&#039;\\&#039;, $class);

        return $name;
    }

    /**
     * 检查配置信息是否完整
     * @return bool
     */
    final public function checkInfo()
    {
        $info_check_keys = array(&#039;name&#039;,&#039;title&#039;,&#039;description&#039;,&#039;status&#039;,&#039;author&#039;,&#039;version&#039;);
        foreach ($info_check_keys as $value) {
            if(!array_key_exists($value, $this-&gt;info))
                return false;
        }
        return true;
    }

    /**
     * 获取插件的配置数组
     */
    final public function getConfig($name = &#039;&#039;)
    {
        static $_config = [];
        if(empty($name)){
            $name = $this-&gt;getName();
        }
        if(isset($_config[$name])){
            return $_config[$name];
        }

        $map[&#039;name&#039;]    =   $name;
        $map[&#039;status&#039;]  =   1;
        $config  =   M(&#039;Addons&#039;)-&gt;where($map)-&gt;getField(&#039;config&#039;);
        if($config){
            $config   =   json_decode($config, true);
        }else{
            $config =   [];
            $temp_arr = include $this-&gt;config_file;
            foreach ($temp_arr as $key =&gt; $value) {
                if($value[&#039;type&#039;] == &#039;group&#039;){
                    foreach ($value[&#039;options&#039;] as $gkey =&gt; $gvalue) {
                        foreach ($gvalue[&#039;options&#039;] as $ikey =&gt; $ivalue) {
                            $config[$ikey] = $ivalue[&#039;value&#039;];
                        }
                    }
                }else{
                    $config[$key] = $temp_arr[$key][&#039;value&#039;];
                }
            }
        }
        $_config[$name]     =   $config;
        return $config;
    }

    /**
     * 必须实现安装
     * @return mixed
     */
    abstract public function install();

    /**
     * 必须卸载插件方法
     * @return mixed
     */
    abstract public function uninstall();
}</code></pre><p>2、在插件表(addons)，钩子表(hooks)中加入相应的数据</p><pre><code class="lang-sql">INSERT INTO `addons` (`id`, `name`, `title`, `description`, `status`, `config`, `author`, `version`, `create_time`, `has_adminlist`) VALUES (&#039;2&#039;, &#039;test&#039;, &#039;test插件&#039;, &#039;test插件简介&#039;, &#039;1&#039;, NULL, &#039;byron sampson&#039;, &#039;0.1&#039;, &#039;1438154545&#039;, &#039;0&#039;);

INSERT INTO .`hooks` (`id`, `name`, `description`, `type`, `update_time`, `addons`, `status`) VALUES (&#039;21&#039;, &#039;demo&#039;, &#039;demo钩子&#039;, &#039;1&#039;, &#039;1384481614&#039;, &#039;test&#039;, &#039;1&#039;);</code></pre><p>3、在addons目录中创建一个test目录，且内部创建一个Test.php插件类</p><pre><code class="lang-php">&lt;?php
// +----------------------------------------------------------------------
// | test [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.zzstudio.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Byron Sampson &lt;xiaobo.sun@gzzstudio.net&gt;
// +----------------------------------------------------------------------
namespace addons\test;

class Test extends \addons\Base
{
    /**
     * 实现demo钩子
     * @param array $params
     */
    public function demo($params = [])
    {
        echo &#039;demo hook!page is &#039; . $params[&#039;p&#039;];
    }

    /**
     * 安装方法
     */
    public function install()
    {
        // TODO: Implement install() method.
    }

    /**
     * 卸载方法
     */
    public function uninstall()
    {
        // TODO: Implement uninstall() method.
    }
}</code></pre><p>4、在控制器中使用hook方法来调用钩子</p><p><code>hook(&#039;demo&#039;, [&#039;p&#039;=&gt;&#039;page&#039;]);</code></p><p>5、ok，大功告成</p><p><img src="https://pic.8oh.com.cn/cos/2022/01/31/bbdda8cacab1b_1643621198.png" alt="180.png" title="180.png"></p><p>来源：<a href="https://blog.zzstudio.net/bs/article_888.html">https://blog.zzstudio.net/bs/article_888.html</a></p>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://dwt.life/archives/188/#comments</comments>
<wfw:commentRss>https://dwt.life/feed/tag/PHP/</wfw:commentRss>
</item>
<item>
<title>ImagickDraw::roundRectangle</title>
<link>https://dwt.life/archives/164/</link>
<guid>https://dwt.life/archives/164/</guid>
<pubDate>Wed, 26 Jan 2022 22:24:17 +0800</pubDate>
<dc:creator>Ricky</dc:creator>
<description><![CDATA[Descriptionpublic ImagickDraw::roundRectangle( float $x1, float $y1, float $x2, float $y2, float ...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<h1>Description</h1><p>public ImagickDraw::roundRectangle(<br> float $x1,<br> float $y1,<br> float $x2,<br> float $y2,<br> float $rx,<br> float $ry<br>): bool<br>Warning<br>这个函数目前还没有被记录下来,只有它的参数列表是可用的。</p><p>给定两个坐标（x和y角半径）并使用当前笔触，笔划宽度和填充设置绘制圆角矩形。</p><p>Parameters<br>x1<br>左上角的X坐标</p><p>y1<br>左上角的Y坐标</p><p>x2<br>右下角的X坐标</p><p>y2<br>右下角的y坐标</p><p>rx<br>x四舍五入</p><p>ry<br>四舍五入</p><p>返回值<br>没有返回任何值。</p><h1>Examples</h1><p>Example #1 ImagickDraw::roundRectangle()例子</p><pre><code class="lang-php">&lt;?php
function roundRectangle($strokeColor, $fillColor, $backgroundColor, $startX, $startY, $endX, $endY, $roundX, $roundY) {

    $draw = new \ImagickDraw();

    $draw-&gt;setStrokeColor($strokeColor);
    $draw-&gt;setFillColor($fillColor);
    $draw-&gt;setStrokeOpacity(1);
    $draw-&gt;setStrokeWidth(2);

    $draw-&gt;roundRectangle($startX, $startY, $endX, $endY, $roundX, $roundY);

    $imagick = new \Imagick();
    $imagick-&gt;newImage(500, 500, $backgroundColor);
    $imagick-&gt;setImageFormat(&quot;png&quot;);

    $imagick-&gt;drawImage($draw);

    header(&quot;Content-Type: image/png&quot;);
    echo $imagick-&gt;getImageBlob();
}

?&gt;</code></pre><p><a href="https://www.php.net/manual/en/imagickdraw.roundrectangle.php">https://www.php.net/manual/en/imagickdraw.roundrectangle.php</a></p>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://dwt.life/archives/164/#comments</comments>
<wfw:commentRss>https://dwt.life/feed/tag/PHP/</wfw:commentRss>
</item>
<item>
<title>PHP生成远程图片缩略图</title>
<link>https://dwt.life/archives/144/</link>
<guid>https://dwt.life/archives/144/</guid>
<pubDate>Fri, 12 Nov 2021 22:03:00 +0800</pubDate>
<dc:creator>Ricky</dc:creator>
<description><![CDATA[&lt;?php  /** **函数：调整图片尺寸或生成缩略图 *返回：True/False *参数：*   $Image   需要调整的图片(含路径) *   $Dw=450  调整时最大宽度...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<pre><code class="lang-php">&lt;?php  
/** 
*
*函数：调整图片尺寸或生成缩略图 
*返回：True/False 
*参数：
*   $Image   需要调整的图片(含路径) 
*   $Dw=450  调整时最大宽度;缩略图时的绝对宽度 
*   $Dh=450  调整时最大高度;缩略图时的绝对高度 
*   $Type=1  1,调整尺寸; 2,生成缩略图 
*/ 
$phtypes=array(&#039;img/gif&#039;, &#039;img/jpg&#039;, &#039;img/jpeg&#039;, &#039;img/bmp&#039;, &#039;img/pjpeg&#039;, &#039;img/x-png&#039;); 

function compressImg($Image,$Dw,$Dh,$Type){  
 
                $Img =@imagecreatefromstring($Image);  

    // 如果对象没有创建成功,则说明非图片文件  
    IF(Empty($Img)){  
        // 如果是生成缩略图的时候出错,则需要删掉已经复制的文件  
        
        return false;  
    }  
    // 如果是执行调整尺寸操作则  
    IF($Type==1){  
        $w=ImagesX($Img);  
        $h=ImagesY($Img);  
        $width = $w;  
        $height = $h;  
        IF($width&gt;$Dw){  
            $Par=$Dw/$width;  
            $width=$Dw;  
            $height=$height*$Par;  
            IF($height&gt;$Dh){  
                $Par=$Dh/$height;  
                $height=$Dh;  
                $width=$width*$Par;  
            }  
        } ElseIF($height&gt;$Dh) {  
            $Par=$Dh/$height;  
            $height=$Dh;  
            $width=$width*$Par;  
            IF($width&gt;$Dw){  
                $Par=$Dw/$width;  
                $width=$Dw;  
                $height=$height*$Par;  
            }  
        } Else {  
            $width=$width;  
            $height=$height;  
        }  
        $nImg =ImageCreateTrueColor($width,$height);// 新建一个真彩色画布  
        ImageCopyReSampled($nImg,$Img,0,0,0,0,$width,$height,$w,$h);// 重采样拷贝部分图像并调整大小  
        ImageJpeg($nImg);// 以JPEG格式将图像输出到浏览器或文件  
        return true;  
    } Else {// 如果是执行生成缩略图操作则  
        $w=ImagesX($Img);  
        $h=ImagesY($Img);  
        $width = $w;  
        $height = $h;  
        $nImg =ImageCreateTrueColor($Dw,$Dh);  
        IF($h/$w&gt;$Dh/$Dw){// 高比较大  
            $width=$Dw;  
            $height=$h*$Dw/$w;  
            $IntNH=$height-$Dh;  
            ImageCopyReSampled($nImg, $Img, 0, -$IntNH/1.8, 0, 0, $Dw, $height, $w, $h);  
        } Else {// 宽比较大  
            $height=$Dh;  
            $width=$w*$Dh/$h;  
            $IntNW=$width-$Dw;  
            ImageCopyReSampled($nImg, $Img,-$IntNW/1.8,0,0,0, $width, $Dh, $w, $h);  
        }  
        ImageJpeg($nImg);  
        return true;  
    }  
};  
  
$arrContextOptions=array(

    &quot;ssl&quot;=&gt;array(

        &quot;verify_peer&quot;=&gt;false,

        &quot;verify_peer_name&quot;=&gt;false,

    ),

); 

 

$imgPath = &#039;https://old.typecho.bearlab.in/usr/uploads/2021/11/4214120057.png&#039;;//远程URL 地址  
header(&#039;Content-Type: image/png&#039;);  
$bigImg=file_get_contents($imgPath, false , stream_context_create($arrContextOptions));//GrabImage($imgPath, $tempPath); 
//echo $bigImg;exit;
compressImg($bigImg,100,100,1);
</code></pre>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://dwt.life/archives/144/#comments</comments>
<wfw:commentRss>https://dwt.life/feed/tag/PHP/</wfw:commentRss>
</item>
<item>
<title>PHP Composer镜像</title>
<link>https://dwt.life/archives/24/</link>
<guid>https://dwt.life/archives/24/</guid>
<pubDate>Sun, 04 Jul 2021 00:53:07 +0800</pubDate>
<dc:creator>Ricky</dc:creator>
<description><![CDATA[composer config -g repo.packagist composer https://packagist.phpcomposer.com]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p><code>composer config -g repo.packagist composer https://packagist.phpcomposer.com</code></p>
]]></content:encoded>
<slash:comments>0</slash:comments>
<comments>https://dwt.life/archives/24/#comments</comments>
<wfw:commentRss>https://dwt.life/feed/tag/PHP/</wfw:commentRss>
</item>
</channel>
</rss>