Dotclear

Changeset 3968:075785b9d306


Ignore:
Timestamp:
05/17/19 12:20:13 (6 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Add WebP image format support to Dotclear (not yet fully tested)

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • .hgsubstate

    r3938 r3968  
    1 c019de4d8ec41f12428c20bd19b2166548802c28 inc/libs/clearbricks 
     1d0492625e961be1bd1b5138de54ef04d68cad199 inc/libs/clearbricks 
  • admin/media_item.php

    r3959 r3968  
    702702} 
    703703 
    704 if ($file->type == 'image/jpeg') { 
     704if ($file->type == 'image/jpeg' || $file->type == 'image/webp') { 
    705705    echo '<h3>' . __('Image details') . '</h3>'; 
    706706 
  • inc/core/class.dc.media.php

    r3958 r3968  
    2525    protected $file_handler = []; ///< <b>array</b> Array of callbacks 
    2626 
    27     public $thumb_tp       = '%s/.%s_%s.jpg'; ///< <b>string</b> Thumbnail file pattern 
    28     public $thumb_tp_alpha = '%s/.%s_%s.png'; ///< <b>string</b> Thumbnail file pattern (with alpha layer) 
    29  
     27    public $thumb_tp       = '%s/.%s_%s.jpg';  ///< <b>string</b> Thumbnail file pattern 
     28    public $thumb_tp_alpha = '%s/.%s_%s.png';  ///< <b>string</b> Thumbnail file pattern (with alpha layer) 
     29    public $thumb_tp_webp  = '%s/.%s_%s.webp'; ///< <b>string</b> Thumbnail file pattern (webp) 
    3030    /** 
    3131    <b>array</b> Tubmnail sizes: 
     
    9494        $this->addFileHandler('image/png', 'create', [$this, 'imageThumbCreate']); 
    9595        $this->addFileHandler('image/gif', 'create', [$this, 'imageThumbCreate']); 
     96        $this->addFileHandler('image/webp', 'create', [$this, 'imageThumbCreate']); 
    9697 
    9798        $this->addFileHandler('image/png', 'update', [$this, 'imageThumbUpdate']); 
    9899        $this->addFileHandler('image/jpeg', 'update', [$this, 'imageThumbUpdate']); 
    99100        $this->addFileHandler('image/gif', 'update', [$this, 'imageThumbUpdate']); 
     101        $this->addFileHandler('image/webp', 'update', [$this, 'imageThumbUpdate']); 
    100102 
    101103        $this->addFileHandler('image/png', 'remove', [$this, 'imageThumbRemove']); 
    102104        $this->addFileHandler('image/jpeg', 'remove', [$this, 'imageThumbRemove']); 
    103105        $this->addFileHandler('image/gif', 'remove', [$this, 'imageThumbRemove']); 
     106        $this->addFileHandler('image/webp', 'remove', [$this, 'imageThumbRemove']); 
    104107 
    105108        $this->addFileHandler('image/jpeg', 'create', [$this, 'imageMetaCreate']); 
     109        $this->addFileHandler('image/webp', 'create', [$this, 'imageMetaCreate']); 
    106110 
    107111        $this->addFileHandler('image/jpeg', 'recreate', [$this, 'imageThumbCreate']); 
    108112        $this->addFileHandler('image/png', 'recreate', [$this, 'imageThumbCreate']); 
    109113        $this->addFileHandler('image/gif', 'recreate', [$this, 'imageThumbCreate']); 
    110  
    111         $this->addFileHandler('image/jpeg', 'recreate', [$this, 'imageThumbCreate']); 
    112         $this->addFileHandler('image/png', 'recreate', [$this, 'imageThumbCreate']); 
    113         $this->addFileHandler('image/gif', 'recreate', [$this, 'imageThumbCreate']); 
     114        $this->addFileHandler('image/webp', 'recreate', [$this, 'imageThumbCreate']); 
    114115 
    115116        # Thumbnails sizes 
     
    294295            $p              = path::info($f->relname); 
    295296 
    296             $alpha = ($p['extension'] == 'png') || ($p['extension'] == 'PNG'); 
    297  
    298             $thumb     = sprintf(($alpha ? $this->thumb_tp_alpha : $this->thumb_tp), $this->root . '/' . $p['dirname'], $p['base'], '%s'); 
    299             $thumb_url = sprintf(($alpha ? $this->thumb_tp_alpha : $this->thumb_tp), $this->root_url . $p['dirname'], $p['base'], '%s'); 
     297            $alpha = strtolower($p['extension']) === 'png'; 
     298            $webp  = strtolower($p['extension']) === 'webp'; 
     299 
     300            $thumb = sprintf( 
     301                ($alpha ? $this->thumb_tp_alpha : 
     302                    ($webp ? $this->thumb_tp_webp : $this->thumb_tp)), 
     303                $this->root . '/' . $p['dirname'], $p['base'], '%s'); 
     304            $thumb_url = sprintf( 
     305                ($alpha ? $this->thumb_tp_alpha : 
     306                    ($webp ? $this->thumb_tp_webp : $this->thumb_tp)), 
     307                $this->root_url . $p['dirname'], $p['base'], '%s'); 
    300308 
    301309            # Cleaner URLs 
     
    303311            $thumb_url = preg_replace('#(?<!:)/+#', '/', $thumb_url); 
    304312 
    305             if ($alpha) { 
     313            if ($alpha || $webp) { 
    306314                $thumb_alt     = sprintf($this->thumb_tp, $this->root . '/' . $p['dirname'], $p['base'], '%s'); 
    307315                $thumb_url_alt = sprintf($this->thumb_tp, $this->root_url . $p['dirname'], $p['base'], '%s'); 
     
    314322                if (file_exists(sprintf($thumb, $suffix))) { 
    315323                    $f->media_thumb[$suffix] = sprintf($thumb_url, $suffix); 
    316                 } elseif ($alpha && file_exists(sprintf($thumb_alt, $suffix))) { 
     324                } elseif (($alpha || $webp) && file_exists(sprintf($thumb_alt, $suffix))) { 
    317325                    $f->media_thumb[$suffix] = sprintf($thumb_url_alt, $suffix); 
    318326                } 
     
    913921        $zip = new fileUnzip($f->file); 
    914922        $zip->setExcludePattern($this->exclude_pattern); 
    915         $list = $zip->getList(false, '#(^|/)(__MACOSX|\.svn|\.DS_Store|\.directory|Thumbs\.db)(/|$)#'); 
     923        $list = $zip->getList(false, '#(^|/)(__MACOSX|\.svn|\.hg|\.git|\.DS_Store|\.directory|Thumbs\.db)(/|$)#'); 
    916924 
    917925        if ($create_dir) { 
     
    965973    { 
    966974        $zip  = new fileUnzip($f->file); 
    967         $list = $zip->getList(false, '#(^|/)(__MACOSX|\.svn|\.DS_Store|\.directory|Thumbs\.db)(/|$)#'); 
     975        $list = $zip->getList(false, '#(^|/)(__MACOSX|\.svn|\.hg|\.git|\.DS_Store|\.directory|Thumbs\.db)(/|$)#'); 
    968976        $zip->close(); 
    969977        return $list; 
     
    9921000 
    9931001        $p     = path::info($file); 
    994         $alpha = ($p['extension'] == 'png') || ($p['extension'] == 'PNG'); 
    995         $thumb = sprintf(($alpha ? $this->thumb_tp_alpha : $this->thumb_tp), $p['dirname'], $p['base'], '%s'); 
     1002        $alpha = strtolower($p['extension']) === 'png'; 
     1003        $webp  = strtolower($p['extension']) === 'webp'; 
     1004        $thumb = sprintf(($alpha ? $this->thumb_tp_alpha : 
     1005            ($webp ? $this->thumb_tp_webp : 
     1006                $this->thumb_tp)), 
     1007            $p['dirname'], $p['base'], '%s'); 
    9961008 
    9971009        try 
     
    10131025                    $rate = ($s[0] < 100 ? 95 : ($s[0] < 600 ? 90 : 85)); 
    10141026                    $img->resize($s[0], $s[0], $s[1]); 
    1015                     $img->output(($alpha ? 'png' : 'jpeg'), $thumb_file, $rate); 
     1027                    $img->output(($alpha || $webp ? strtolower($p['extension']) : 'jpeg'), $thumb_file, $rate); 
    10161028                    $img->loadImage($file); 
    10171029                } 
     
    10301042        if ($file->relname != $newFile->relname) { 
    10311043            $p         = path::info($file->relname); 
    1032             $alpha     = ($p['extension'] == 'png') || ($p['extension'] == 'PNG'); 
    1033             $thumb_old = sprintf(($alpha ? $this->thumb_tp_alpha : $this->thumb_tp), $p['dirname'], $p['base'], '%s'); 
     1044            $alpha     = strtolower($p['extension']) === 'png'; 
     1045            $webp      = strtolower($p['extension']) === 'webp'; 
     1046            $thumb_old = sprintf(($alpha ? $this->thumb_tp_alpha : 
     1047                ($webp ? $this->thumb_tp_webp : 
     1048                    $this->thumb_tp)), 
     1049                $p['dirname'], $p['base'], '%s'); 
    10341050 
    10351051            $p         = path::info($newFile->relname); 
    1036             $alpha     = ($p['extension'] == 'png') || ($p['extension'] == 'PNG'); 
    1037             $thumb_new = sprintf(($alpha ? $this->thumb_tp_alpha : $this->thumb_tp), $p['dirname'], $p['base'], '%s'); 
     1052            $alpha     = strtolower($p['extension']) === 'png'; 
     1053            $webp      = strtolower($p['extension']) === 'webp'; 
     1054            $thumb_new = sprintf(($alpha ? $this->thumb_tp_alpha : 
     1055                ($webp ? $this->thumb_tp_webp : 
     1056                    $this->thumb_tp)), 
     1057                $p['dirname'], $p['base'], '%s'); 
    10381058 
    10391059            foreach ($this->thumb_sizes as $suffix => $s) { 
     
    10481068    { 
    10491069        $p     = path::info($f); 
    1050         $alpha = ($p['extension'] == 'png') || ($p['extension'] == 'PNG'); 
    1051         $thumb = sprintf(($alpha ? $this->thumb_tp_alpha : $this->thumb_tp), '', $p['base'], '%s'); 
     1070        $alpha = strtolower($p['extension']) === 'png'; 
     1071        $webp  = strtolower($p['extension']) === 'webp'; 
     1072        $thumb = sprintf(($alpha ? $this->thumb_tp_alpha : 
     1073            ($webp ? $this->thumb_tp_webp : 
     1074                $this->thumb_tp)), 
     1075            '', $p['base'], '%s'); 
    10521076 
    10531077        foreach ($this->thumb_sizes as $suffix => $s) { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map