良百科

枯榆绕屋,迎门绿竹。

用户工具

站点工具

  • write
  • everyday
  • yufa
  • poem
  • template
  • syntax
  • random
  • xiangfen
  • baidu
  • 抱歉,您没有权限增加页面

    jackboodigest:code:watermark_image_component_for_cakephp

    Watermark & Image Component for CakePHP

    Note: This Component has been updated and you can find the changes here: /2011/04/clase-php-para-tratar-imagenes-rotar-redimensionar-anadir-marcas-de-agua/

    Time ago I created a CakePHP component for applying watermarks to images. Slowly I extended it and now in addition to applying watermarks is used to rotate and resize images.

    You can still improve it a lot, especially in terms of code, but as it works and I have little time, I can barely make improvements.

    Tested from: Linux php 5.2.10 Linux php 5.2.13 Windows php 5.3.1 Windows php 5.3.2 Well Known Bugs: Uses the method mime_content_type that as they say in php.net: This function has been deprecated as the PECL extension Fileinfo provides the same functionality (and more) in a much cleaner way. [ SOLVED ] By rotating a transparent PNG image at an angle that is not a multiple of 90º the extra generated background is not transparent. Download: http://github.com/elboletaire/Watimage/archives/master

    Usage: 01 <?php /app/controllers/foo_controller.php 02 class FooController extends AppController 03 { 04 var $name = “Foo”; 05 Remember to initialize the component 06

    var $components = array("Watermark");

    07

    08

    public function upload()

    09

    {

    10

      // ... upload stuff

    11

      if ( $is_uploaded )

    12

      {

    13

        $this->Watermark->setImage($image_path);

    14

        $this->Watermark->resize(array('type' => 'resizecrop', 'size' => array(450,450)));

    15

        $this->Watermark->generate($dest_path);

    16

        // ... more stuff ...

    17

      }

    18

    }

    19 } Original files used for demonstrations:

    Resize:

    1 $this→Watermark→setImage($image_path); 2 $this→Watermark→resize(array('type' ⇒ 'resizecrop'), 'size' ⇒ array('300', '200')); 3 $this→Watermark→generate($dest_path); Resize types: resize: Maintains the aspect ratio of the image and makes sure that it fits within the max width and max height (thus some side will be smaller). resizemin: Maintains aspect ratio but resizes the image so that once one side meets its max width or max height condition, it stays at that size (thus one side will be larger). resizecrop: Resize to max, then crop to center. crop: A straight centered crop. * Resizing criteria extracted from iamkoa labs image upload component

    Rotate:

    1 $this→Watermark→setImage($image_path); 2 $this→Watermark→rotateImage(array('degrees' ⇒ 45)); 3 $this→Watermark→generate($dest_path); Apply watermark:

    1 $this→Watermark→setImage($image_path); 2 $this→Watermark→setWatermark(array('file' ⇒ $watermark_file, 'position' ⇒ 'bottom right', 'size' ⇒ '150%')); 3 $this→Watermark→applyWatermark(); 4 $this→Watermark→generate($dest_path); All together:

    1 $this→Watermark→setImage($image_path); 2 $this→Watermark→setWatermark(array('file' ⇒ 'watermark.png', 'position' ⇒ 'bottom right', 'size' ⇒ '150%')); 3 $this→Watermark→resize(array('type' ⇒ 'resizecrop', 'size' ⇒ array('300', '200'))); 4 $this→Watermark→applyWatermark(); 5 $this→Watermark→rotateImage(array('degrees' ⇒ 45, 'bgcolor' ⇒ 0)); 6 $this→Watermark→generate($dest_path); Changing order:

    1 $this→Watermark→setImage($image_path); 2 $this→Watermark→setWatermark(array('file' ⇒ 'watermark.png', 'position' ⇒ 'bottom right', 'size' ⇒ '150%')); 3 $this→Watermark→rotateImage(array('degrees' ⇒ 45, 'bgcolor' ⇒ 0)); 4 $this→Watermark→resize(array('type' ⇒ 'resizecrop', 'size' ⇒ array('300', '200'))); 5 $this→Watermark→applyWatermark(); 6 $this→Watermark→generate($dest_path); Show image instead of saving it: 1 $this→Watermark→setImage($image_path); 2 $this→Watermark→generate(); Without params With errors: 01 every component method return false on error 02 if ( !$this→Watermark→setImage($image_path) ) 03 { 04

    // whatever

    05

    print_r($this->Watermark->errors);

    06 } 07

    08 if ( !$this→Watermark→resize(array('type' ⇒ 'resizecrop', 'size' ⇒ 250)) ) 09 { 10

    // ...

    11 } 12

    13 if ( !$this→Watermark→generate() ) 14 { 15

    // ...

    16 } Entrades relacionades:

    Clase PHP para tratar imágenes (rotar, redimensionar, añadir marcas de agua..) CakePHP Auth Component ajaxLogin Validar datos duplicados en CakePHP Subida de ficheros en CakePHP 1.2 con uploadify y jQuery Errores 404 con Ajax (y jQuery) en CakePHP

    使用的这个模板很简介。http://www.neoease.com/

    neoease的wordpress模板很简洁,喜欢。

    2020年1月8日15:21:43 http://www.racotecnic.com/2010/04/watermark-image-component-for-cakephp/

    jackboodigest/code/watermark_image_component_for_cakephp.txt · 最后更改: 2020/01/08 15:22 由 jackboo