Bildgröße proportional ändern?

moistwanted

Erfahrenes Mitglied
Moinsen

Also ich hab folgendes Problem:

ICh will in meine Seite ein bilderuploadscript per php einbauen.
Die User sollen dann Bilder hochladen können!

Problem 1:
Manche Bilder wie zB Avatar sollen gleich nur eine bestimmte Größe (Höhe/Breite) haben können!

Problem 2:
Andere Bilder sollen komplett hochgeladen werde, aber dann bei der Ausgabe proportional
verkleinert werden!

Wie kann ich das machen?
Kann ich irgendwie die Bildgröße auslesen?

Vielen Dank im Voraus
moistwanted
 
PHP:
	class thumb 
	{ 
		var $im = 0; 
	
		function thumb($file=0, $width=0, $height=0) 
		{ 
			if ($file && $width && $height) { 
				$this->create($file, $width, $height); 
			} 
		} 
	
		function create($file, $width=0, $height=0, $resample=0) 
		{ 
			if ($this->im) $this->clear(); 
	
			list($src_width, $src_height, $src_type) = getimagesize($file); 
			if ($src_type != 2) return false; // kein jpeg => abbrechen 
			 
			if ($width == 0) { 
				$width = round($height * ($src_width/$src_height)); 
			} 
			if ($height == 0) { 
				$height = round($width * ($src_height/$src_width)); 
			} 
			 
			$src_im = imagecreatefromjpeg($file); 
			$this->im = imagecreatetruecolor($width, $height); 
			 
			if ($resample) { 
				imagecopyresampled($this->im, $src_im, 0, 0, 0, 0, 
					$width, $height, $src_width, $src_height); 
			} else { 
				imagecopyresized($this->im, $src_im, 0, 0, 0, 0, 
					$width, $height, $src_width, $src_height); 
			} 
			 
			imagedestroy($src_im); 
					 
			return true; 
		} 
	
		function savetofile($file, $quality=75) 
		{ 
			imagejpeg($this->im, $file, $quality); 
		} 
	
		function output($quality=75) 
		{ 
			header("Content-type: image/jpeg"); 
			imagejpeg($this->im, "", $quality); 
		} 
	
		function clear() 
		{ 
			imagedestroy($this->im); 
			$this->im = 0; 
		} 
	}

PHP:
$thumb1 = new thumb();
$thumb1->create($filename, $x ,0, 1); // wenn x oder y == 0 dann wird propotional gemacht
$thumb1->savetofile($new_filename, 100); 
$thumb1->clear();

ich hoffe das hilft
 
Zurück