Changeset 14735


Ignore:
Timestamp:
May 4, 2012, 6:29:44 AM (8 years ago)
Author:
rvelices
Message:

multi size - don't fail if image metadata was not previously synced

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/derivative.inc.php

    r14143 r14735  
    2424  const IS_ORIGINAL = 0x01;
    2525  const IS_MIMETYPE = 0x02;
     26  const DIM_NOT_GIVEN = 0x04;
    2627
    2728  public $id;
     
    5253      $this->rel_path = trigger_event('get_mimetype_location', get_themeconf('mime_icon_dir').$ext.'.png', $ext );
    5354      $this->flags |= self::IS_MIMETYPE;
    54       $this->size = @getimagesize(PHPWG_ROOT_PATH.$this->rel_path);
    55     }
    56 
    57     if (!$this->size && isset($infos['width']) && isset($infos['height']))
    58     {
    59       $width = $infos['width'];
    60       $height = $infos['height'];
    61 
    62       $this->rotation = intval($infos['rotation']) % 4;
    63       // 1 or 5 =>  90 clockwise
    64       // 3 or 7 => 270 clockwise
    65       if ($this->rotation % 2)
    66       {
    67         $width = $infos['height'];
    68         $height = $infos['width'];
    69       }
    70      
    71       $this->size = array($width, $height);
     55      if ( ($size=@getimagesize(PHPWG_ROOT_PATH.$this->rel_path)) === false)
     56      {
     57        $this->rel_path = get_themeconf('mime_icon_dir').'unknown.png';
     58        $size = getimagesize(PHPWG_ROOT_PATH.$this->rel_path);
     59      }
     60      $this->size = array($size[0],$size[1]);
     61    }
     62
     63    if (!$this->size)
     64    {
     65      if (isset($infos['width']) && isset($infos['height']))
     66      {
     67        $width = $infos['width'];
     68        $height = $infos['height'];
     69
     70        $this->rotation = intval($infos['rotation']) % 4;
     71        // 1 or 5 =>  90 clockwise
     72        // 3 or 7 => 270 clockwise
     73        if ($this->rotation % 2)
     74        {
     75          $width = $infos['height'];
     76          $height = $infos['width'];
     77        }
     78       
     79        $this->size = array($width, $height);
     80      }
     81      elseif (!array_key_exists('width', $infos))
     82      {
     83        $this->flags |= self::DIM_NOT_GIVEN;
     84      }
    7285    }
    7386  }
     
    106119  {
    107120    if ($this->size == null)
    108       not_implemented(); // get size from file
     121    {
     122      if ($this->flags & self::DIM_NOT_GIVEN)
     123        fatal_error('SrcImage dimensions required but not provided');
     124      // probably not metadata synced
     125      if ( ($size = getimagesize( $this->get_path() )) !== false)
     126      {
     127        $this->size = array($size[0],$size[1]);
     128        pwg_query('UPDATE '.IMAGES_TABLE.' SET width='.$size[0].', height='.$size[1].' WHERE id='.$this->id);
     129      }
     130    }
    109131    return $this->size;
    110132  }
Note: See TracChangeset for help on using the changeset viewer.