To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Changeset 1078

Show
Ignore:
Timestamp:
04/27/10 15:49:28 (22 months ago)
Author:
tboutell
Message:

New aImageConverter::supportsInput($extension) method allows you to check whether aImageConverter can import a particular image format on this system. Mainly used to check for pdf support:

if (aImageConverter::supportsInput('pdf')) { ... }

You can pass:

gif, jpg, jpeg, png, bmp, ico, pdf (pdf always reports false if ghostscript is not available) and, if you have the netpbm utilities, other well known file extensions supported by netpbm.

This method can of course be fooled by broken installations in which the netpbm utilities or ghostscript are present but not working.

Lack of support for bmp and ico is neither a bug nor uncommon.

For performance reasons the result is cached for 5 minutes. Keep that in mind if you make system changes such as installing netpbm and ghostscript and see no immediate difference.

Location:
plugins/apostrophePlugin/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePlugin/trunk

  • plugins/apostrophePlugin/trunk/lib/toolkit/aFeed.class.php

    r279 r1078  
    99         * http://spindrop.us/2006/07/04/dynamic-linking-to-syndication-feeds-with-symfony/ 
    1010         * 
    11          * @author Dave Dash 
     11         * @author Dave Dash (just this method) 
    1212         * 
    1313         * Unrelated to aFeed slots. 
  • plugins/apostrophePlugin/trunk/lib/toolkit/aImageConverter.class.php

    r430 r1078  
    461461    return false; 
    462462  } 
     463   
     464  // Can this box handle pdf, png, jpeg (also acdepts jpg), gif, bmp, ico... 
     465 
     466  // Mainly used to check for PDF support. 
     467   
     468  // NOTE: this call is a performance hit, especially with netpbm and ghostscript available. 
     469  // So we cache the result for 5 minutes. Keep that in mind if you make configuration changes, install 
     470  // ghostscript, etc. and don't see an immediate difference. 
     471 
     472  static public function supportsInput($extension) 
     473  { 
     474    $hint = aImageConverter::getHint("input:$extension"); 
     475    if (!is_null($hint)) 
     476    { 
     477      return $hint; 
     478    } 
     479     
     480    $result = false; 
     481    if (sfConfig::get('app_aimageconverter_netpbm', true)) 
     482    { 
     483      if (aImageConverter::supportsInputNetpbm($extension)) 
     484      { 
     485        $result = true; 
     486      } 
     487    } 
     488    if (!$result) 
     489    { 
     490      $result = aImageConverter::supportsInputGd($extension); 
     491    } 
     492    aImageConverter::setHint("input:$extension", $result); 
     493    return $result; 
     494  } 
     495 
     496  static public function supportsInputNetpbm($extension) 
     497  { 
     498    $types = array('gif' => 'gif', 'png' => 'png', 'jpg' => 'jpeg', 'jpeg' => 'jpeg', 'bmp' => 'bmp', 'ico' => 'ico'); 
     499    $path = sfConfig::get("app_aimageconverter_path", ""); 
     500    if (strlen($path)) { 
     501      if (!preg_match("/\/$/", $path)) { 
     502        $path .= "/"; 
     503      } 
     504    } 
     505    if ($extension === 'pdf') 
     506    { 
     507      $cmd = 'gs'; 
     508    } 
     509    elseif (!isset($types[$extension])) 
     510    { 
     511      if (!preg_match('/^\w+$/', $extension)) 
     512      { 
     513        return false; 
     514      } 
     515      $cmd = $extension . 'topnm'; 
     516    } 
     517    else 
     518    { 
     519      $cmd = $types[$extension] . 'topnm'; 
     520    } 
     521    $in = popen("(PATH=$path:\$PATH; export PATH; which $cmd)", "r"); 
     522    $result = stream_get_contents($in); 
     523    pclose($in); 
     524    if (strlen($result)) 
     525    { 
     526      return true; 
     527    } 
     528    return false; 
     529  } 
     530   
     531  static public function supportsInputGd($extension) 
     532  { 
     533    $types = array('gif' => 'gif', 'png' => 'png', 'jpg' => 'jpeg', 'jpeg' => 'jpeg', 'bmp' => 'bmp', 'ico' => 'ico'); 
     534    if (!isset($types[$extension])) 
     535    { 
     536      return false; 
     537    } 
     538    $f = 'imagecreatefrom' . $types[$extension]; 
     539    return is_callable($f); 
     540  } 
     541   
     542  static public function getHint($hint) 
     543  { 
     544    $cache = aImageConverter::getHintCache(); 
     545    $key = 'apostrophe:imageconverter:' . $hint; 
     546    return $cache->get($key, null); 
     547  } 
     548   
     549  static public function setHint($hint, $value) 
     550  { 
     551    $cache = aImageConverter::getHintCache(); 
     552    // The lifetime should be short to avoid annoying developers who are 
     553    // trying to fix their configuration and test with new possibilities 
     554    $key = 'apostrophe:imageconverter:' . $hint; 
     555    $cache->set($key, $value, 300); 
     556  } 
     557  static public function getHintCache() 
     558  { 
     559    $cacheClass = sfConfig::get('app_a_hint_cache_class', 'sfFileCache'); 
     560    $cache = new $cacheClass(sfConfig::get('app_a_hint_cache_options', array('cache_dir' => aFiles::getWritableDataFolder(array('a_hint_cache'))))); 
     561    return $cache; 
     562  } 
    463563} 
  • plugins/apostrophePlugin/trunk/web/css/a.css

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • plugins/apostrophePlugin/trunk/web/images

    • Property svn:mergeinfo changed (with no actual effect on merging)