webForumDet fria alternativet

Skala bild

7 svar · 447 visningar · startad av Flow

FlowMedlem sedan dec. 200283 inlägg
#1

Någon som kan förklara varför denna funktion inte fungerar på bilder som är större än 1500-2000 pixlar i bredd?

	function scaleImage($userfile_name, $width_size, $userfile_type)
	{		

		///////// Start the thumbnail generation//////////////
				$image_stats = GetImageSize("$userfile_name");
				$original_height = $image_stats[1];
				$original_width = $image_stats[0];
				
				echo "original width: " . $image_stats[0] . " height: " . $image_stats[1];
				
				//if($original_width>=430) {
				
				if($original_width>=$width_size) {
					
				$n_width=$width_size;          // Fix the width of the thumb nail images
				$ratio = ($original_width / $original_height);

				//$n_height=100;         // Fix the height of the thumb nail imaage
				$n_height = round($n_width / $ratio);
				
				/*
				echo "Original height: $original_height<br>";
				echo "Ratio: $ratio<br>";
				echo "N_width: $n_width<br>";
				echo "N_height: $n_height<br>";
				*/
				$tsrc="$userfile_name";   // Path where thumb nail image will be stored
				//echo $tsrc;

				if (!($userfile_type =="image/pjpeg" OR $userfile_type=="image/gif")){echo "Your uploaded file must be of JPG or GIF. Other file types are not allowed!<BR>";
				//exit;
				}
				/////////////////////////////////////////////// Starting of GIF thumb nail creation///////////
				if (@$userfile_type=="image/gif")
				{
				$im=ImageCreateFromGIF($userfile_name);
				$width=ImageSx($im);              // Original picture width is stored
				$height=ImageSy($im);             // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				if (function_exists("imagegif")) {
				Header("Content-type: image/gif");
				ImageGIF($newimage,$tsrc);
				}
				elseif (function_exists("imagejpeg")) {
				Header("Content-type: image/jpeg");
				ImageJPEG($newimage,$tsrc);
				}
				chmod("$tsrc",0777);
				}////////// end of gif file thumb nail creation//////////
				
				////////////// starting of JPG thumb nail creation//////////
				if($userfile_type=="image/pjpeg"){
				$im=ImageCreateFromJPEG($userfile_name); 
				$width=ImageSx($im);              // Original picture width is stored
				$height=ImageSy($im);             // Original picture height is stored
				$newimage=imagecreatetruecolor($n_width,$n_height);                 
				imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
				ImageJpeg($newimage,$tsrc);
				chmod("$tsrc",0777);
				}
				////////////////  End of JPG thumb nail creation //////////			
				}	
		}
GislavedMedlem sedan nov. 20041 740 inlägg
#2

Har du provat att byta ut imageCopyResized mot imagecopyresampled?

tydalMedlem sedan juni 20034 013 inlägg
#3

Om du berättade vad det blev för fel så skulle vi kunna ha en möjlighet att förklara. Nu kan vi bara gissa.

Jag gissar dock på att minnesgränsen för skript överskrids. (Sätts i php.ini memory_limit)

FlowMedlem sedan dec. 200283 inlägg
#4

Hej!, Får inget felmeddelande, skriptet stoppar sig själv och lämnar inget meddelande alls, precis som om man hade skrivit exit();

Pröva imagecopyresampled men det fungerade inte heller... Om jag tvingar och sätter bredden och höjden till 100x100 så fungererar det, men inte när scriptet läser av höjden och bredden och gör en "ratio" på det.

Har även kollat så att den kan läsa bildbredd och höjd och det gör den...

pettssonMedlem sedan jan. 20021 122 inlägg
#5

Laddar du upp en bild med typ image/pjpeg då? Har för mig att det betyder progressiv jpeg, pröva att lägga till typen image/jpeg i if-satsen.
/r:
pjpeg var inte progressiv jpeg, men lägg ändå till image/jpeg i listan, verkar vara lite beroende på vilket program som sparade bilden vilken typ den får

FlowMedlem sedan dec. 200283 inlägg
#6

Har lagt in en echo rad efter varje kommando som utförs och den stannar på följande rad:

				$newimage=imagecreatetruecolor($n_width,$n_height);
FlowMedlem sedan dec. 200283 inlägg
#7

Lade till detta:

ini_set('memory_limit', '20M');

och nu fungerar det!

pettssonMedlem sedan jan. 20021 122 inlägg
#8

/r:
Bleh. Läste fel. Glöm det.

129 ms totalt · 3 externa anrop · v20260731065814-full.0e50b1ef
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
126 ms — hämta tråd, inlägg och bilagor (db)