<commit_before><?php

/**
 * Bild
 * 
 * This class has been auto-generated by the Doctrine ORM Framework
 * 
 * @package    openZIM
 * @subpackage model
 * @author     Your name here
 * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
 */
class Bild extends BaseBild
{
	public function save(Doctrine_Connection $conn = null)
	{
		$this->imageScale();

		if ( !$this->getPath() )
			$this->delete();
		else
	 		$ret = parent::save($conn);
		return $ret;
	}  

	public function imageScale()
	{

		$path = '/'.(sfConfig::get('sf_upload_dir')).'/bilder/'.$this->getPath();

		$filename = $path;
		$image_info = getimagesize($filename);
		$image_type = $image_info[2];
      	
		// Bild laden	
		if( $image_type == IMAGETYPE_JPEG ) {
         		$image = imagecreatefromjpeg($filename);
      		} elseif( $image_type == IMAGETYPE_GIF ) {
         		$image = imagecreatefromgif($filename);
      		} elseif( $image_type == IMAGETYPE_PNG ) {
         		$image = imagecreatefrompng($filename);
      		}

		// Bild Skalieren	        	
      		$height = imagesy($image);
		$width = imagesx($image);

		if( $width > 600 ) {
			$ratio = $width / $height;
			$new_width = 600;
			$new_height = $new_width / $ratio;
		}

		$new_image = imagecreatetruecolor($new_width, $new_height);
      		imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
      		$image = $new_image;   
   
		// Bild sichern
	 	if( $image_type == IMAGETYPE_JPEG ) {
                        imagejpeg($image, $filename, 100);
                } elseif( $image_type == IMAGETYPE_GIF ) {
                        imagegif($image, $filename);
                } elseif( $image_type == IMAGETYPE_PNG ) {
                        imagepng($image, $filename);
                }
	}

}<commit_msg>Bild.class: fix scaling for small images<commit_after><?php

/**
 * Bild
 * 
 * This class has been auto-generated by the Doctrine ORM Framework
 * 
 * @package    openZIM
 * @subpackage model
 * @author     Your name here
 * @version    SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
 */
class Bild extends BaseBild
{
	public function save(Doctrine_Connection $conn = null)
	{
		$this->imageScale();

		if ( !$this->getPath() )
			$this->delete();
		else
	 		$ret = parent::save($conn);
		return $ret;
	}  

	public function imageScale()
	{

		$path = '/'.(sfConfig::get('sf_upload_dir')).'/bilder/'.$this->getPath();

		$filename = $path;
		$image_info = getimagesize($filename);
		$image_type = $image_info[2];
      	
		// Bild laden	
		if( $image_type == IMAGETYPE_JPEG ) {
         		$image = imagecreatefromjpeg($filename);
      		} elseif( $image_type == IMAGETYPE_GIF ) {
         		$image = imagecreatefromgif($filename);
      		} elseif( $image_type == IMAGETYPE_PNG ) {
         		$image = imagecreatefrompng($filename);
      		}

		// Bild Skalieren	        	
      		$height = imagesy($image);
		$width = imagesx($image);
		
		$new_width  = $width;
		$new_height = $height;
		if( $width > 600 ) {
			$ratio = $width / $height;
			$new_width = 600;
			$new_height = $new_width / $ratio;
		}

		$new_image = imagecreatetruecolor($new_width, $new_height);
      		imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
      		$image = $new_image;   
   
		// Bild sichern
	 	if( $image_type == IMAGETYPE_JPEG ) {
                        imagejpeg($image, $filename, 100);
                } elseif( $image_type == IMAGETYPE_GIF ) {
                        imagegif($image, $filename);
                } elseif( $image_type == IMAGETYPE_PNG ) {
                        imagepng($image, $filename);
                }
	}

}
{'fraction_non_alphanumeric': 0.14595767769940315, 'fraction_numerical': 0.017362995116657624, 'mean_word_length': 2.4075785582255085, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3202221', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1297, 'n_words': 257}