<commit_before><?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

// +----------------------------------------------------------------------+
// | Akelos Framework - http://www.akelos.org                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006, Akelos Media, S.L.  & <NAME> |
// | Released under the GNU Lesser General Public License, see LICENSE.txt|
// +----------------------------------------------------------------------+

/**
 * @package AkelosFramework
 * @subpackage AkImage
 * @author <NAME> <bermi a.t akelos c.om>
 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
 */

 defined('AK_IMAGE_DRIVER') ? null : define('AK_IMAGE_DRIVER', 'GD');

 require_once(AK_VENDOR_DIR.DS.'pear'.DS.'Image'.DS.'Transform.php');
 require_once(AK_LIB_DIR.DS.'AkImage'.DS.'AkImageFilter.php');

 class AkImage extends Image_Transform
 {
     var $image_path;
     var $Transform;
     var $filters = array();

     function AkImage($image_path = null, $tranform_using = AK_IMAGE_DRIVER)
     {
         $this->Transform =& Image_Transform::factory($tranform_using);
         if (PEAR::isError($this->Transform)){
             trigger_error($this->Transform->getMessage(), E_USER_ERROR);
         }
         if(!empty($image_path)){
             $this->load($image_path);
         }
     }

     function load($image_path)
     {
         $this->image_path = $image_path;
         $this->Transform->load($image_path);
     }

     function save($path = null, $quality = 90, $options = array())
     {
         if(!$tmp_image_name = tempnam(AK_CACHE_DIR,'ak_image_')){
             trigger_error(Ak::t('Could not create the temporary file %tmp_image_name for apliying changes and saving', array('%tmp_image_name'=>$tmp_image_name)), E_USER_ERROR);
         }
         
         $path = empty($path) ? $this->image_path : $path;
         $this->Transform->save($tmp_image_name, $this->getExtension($path), $quality);         
         Ak::file_put_contents($path, file_get_contents($tmp_image_name), $options);
         @unlink($tmp_image_name);
     }
<commit_msg>Adding GD availability check as PEAR::Image_Transform does not raise errors correctly on PHP5<commit_after><?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

// +----------------------------------------------------------------------+
// | Akelos Framework - http://www.akelos.org                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006, Akelos Media, S.L.  & <NAME> |
// | Released under the GNU Lesser General Public License, see LICENSE.txt|
// +----------------------------------------------------------------------+

/**
 * @package AkelosFramework
 * @subpackage AkImage
 * @author <NAME> <bermi a.t akelos c.om>
 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
 */

 defined('AK_IMAGE_DRIVER') ? null : define('AK_IMAGE_DRIVER', 'GD');

 require_once(AK_VENDOR_DIR.DS.'pear'.DS.'Image'.DS.'Transform.php');
 require_once(AK_LIB_DIR.DS.'AkImage'.DS.'AkImageFilter.php');

 class AkImage extends Image_Transform
 {
     var $image_path;
     var $Transform;
     var $filters = array();

     function AkImage($image_path = null, $tranform_using = AK_IMAGE_DRIVER)
     {
         if(!function_exists('getimagesize')){
             trigger_error(Ak::t('GD library is not available.'), E_USER_ERROR);
         }
         
         $this->Transform =& Image_Transform::factory($tranform_using);
         
         if(PEAR::isError($this->Transform)){
             trigger_error($this->Transform->getMessage(), E_USER_ERROR);
         }
         if(!empty($image_path)){
             $this->load($image_path);
         }
     }

     function load($image_path)
     {
         $this->image_path = $image_path;
         $this->Transform->load($image_path);
     }

     function save($path = null, $quality = 90, $options = array())
     {
         if(!$tmp_image_name = tempnam(AK_CACHE_DIR,'ak_image_')){
             trigger_error(Ak::t('Could not create the temporary file %tmp_image_name for apliying changes and saving', array('%tmp_image_name'=>$tmp_image_name)), E_USER_ERROR);
         }
         
         $path = empty($path) ? $this->image_path : $path;
         $this->Transform->save($tmp_image_name, $this->getExtension($path), $quality);         
         Ak::file_put_contents($path, file_get_contents($tmp_image_name), $options);
         @unlink($tmp_image_name);
     }

{'fraction_non_alphanumeric': 0.2269681742043551, 'fraction_numerical': 0.009003350083752094, 'mean_word_length': 2.12630890052356, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2589622', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1395, 'n_words': 260}