<commit_before><?php
/**
 * Automatically scale down uploaded images
 * ========================================
 *
 * Extension to automatically scale down uploaded images to a maximum
 * of pre-determined values or defaults. It also includes auto-rotation
 * based on EXIF data (eg: images from digital cameras).
 *
 * Options:
 * Please refer to the README.md
 *
 * @license: MIT-style license http://opensource.org/licenses/MIT
 * @author: Techno Joy development team (www.technojoy.co.nz)
 */

class ScaledUploads extends DataExtension {

	public static $max_width = 960;
	public static $max_height = 800;
	public static $exif_rotation = true;

	public function onAfterWrite() {
		$this->ScaleUpload();
	}

	public function getMaxWidth() {
		$w = Config::inst()->get('ScaledUploads', 'max-width');
		return ($w) ? $w : self::$max_width;
	}

	public function getMaxHeight() {
		$h = Config::inst()->get('ScaledUploads', 'max-height');
		return ($h) ? $h : self::$max_height;
	}

	public function getMinSize() {
		return ($this->getMaxWidth() > $this->getMaxHeight()) ? $this->getMaxHeight() : $this->getMaxWidth();
	}

	public function getAutoRotate() {
		$r = Config::inst()->get('ScaledUploads', 'auto-rotate');
		if ($r === 0 || $r == 'false') return false;
		return self::$exif_rotation;
	}

	public function ScaleUpload() {
		$extension = strtolower($this->owner->getExtension());

		if($this->owner->getHeight() > $this->getMinSize() || $this->owner->getWidth() > $this->getMinSize()) {
			$original = $this->owner->getFullPath();
			$resampled = $original . '.tmp.' . $extension;
			$gd = new GD($original);
			if($gd->hasGD()) {
				/* Clone original */
				$transformed = $gd;<commit_msg>Fix bug<commit_after><?php
/**
 * Automatically scale down uploaded images
 * ========================================
 *
 * Extension to automatically scale down uploaded images to a maximum
 * of pre-determined values or defaults. It also includes auto-rotation
 * based on EXIF data (eg: images from digital cameras).
 *
 * Options:
 * Please refer to the README.md
 *
 * @license: MIT-style license http://opensource.org/licenses/MIT
 * @author: Techno Joy development team (www.technojoy.co.nz)
 */

class ScaledUploads extends DataExtension {

	public static $max_width = 960;
	public static $max_height = 800;
	public static $exif_rotation = true;

	public function onAfterWrite() {
		$this->ScaleUpload();
	}

	public function getMaxWidth() {
		$w = Config::inst()->get('ScaledUploads', 'max-width');
		return ($w) ? $w : self::$max_width;
	}

	public function getMaxHeight() {
		$h = Config::inst()->get('ScaledUploads', 'max-height');
		return ($h) ? $h : self::$max_height;
	}

	public function getAutoRotate() {
		$r = Config::inst()->get('ScaledUploads', 'auto-rotate');
		if ($r === 0 || $r == 'false') return false;
		return self::$exif_rotation;
	}

	public function ScaleUpload() {
		$extension = strtolower($this->owner->getExtension());

		if($this->owner->getHeight() > $this->getMaxHeight() || $this->owner->getWidth() > $this->getMaxWidth()) {
			$original = $this->owner->getFullPath();
			$resampled = $original . '.tmp.' . $extension;
			$gd = new GD($original);
			if($gd->hasGD()) {
				/* Clone original */
				$transformed = $gd;
{'fraction_non_alphanumeric': 0.19146977600490947, 'fraction_numerical': 0.004295796256520405, 'mean_word_length': 4.3618421052631575, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7020576', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1016, 'n_words': 264}