【问题标题】:Change the size of the captcha image in yii在 yii 中更改验证码图像的大小
【发布时间】:2015-10-14 12:47:41
【问题描述】:

我想在 yii 中更改验证码图像的大小。我知道宽度最初设置为 100。我想让它变大两倍。我无法使用以下代码进行任何更改。

<?php $this->widget('CCaptcha',array('buttonOptions'=>array('style'=>'width:200'))); 

【问题讨论】:

    标签: yii


    【解决方案1】:

    如果要更改图像大小,则应使用imageOptions 而不是buttonOptions,例如:

    <?php $this->widget('CCaptcha', array('imageOptions' => array('style'=>'width:20%'))); ?>
    

    查看CCaptcha 文档。

    【讨论】:

    • 请注意,这会将图像拉伸到设置的大小
    【解决方案2】:

    您可以自然地实现这一点,而无需为图像元素设置样式。在SiteController 中,您有actions() 方法,该方法返回captcha 内置操作的选项数组。

    public function actions()
    {
        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            'captcha'=>array(
                'class'=>'CCaptchaAction',
                'backColor'=>0xFFFFFF,
                'width' => '..' // <- Set this to override a default width
            ),
    

    然后在没有参数的情况下渲染它:

    <?php $this->widget('CCaptcha'); ?>
    

    【讨论】:

      【解决方案3】:

      是通过模板解决的 PHP:

              <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), ['template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>']) ?>
      

      JS:

          document.getElementById("reviews-verifycode-image").style.height = "100px";
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-21
        • 2015-06-11
        • 1970-01-01
        • 1970-01-01
        • 2014-09-16
        • 1970-01-01
        • 2013-01-18
        相关资源
        最近更新 更多