PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : imagecopy(....) Fehlermeldung... :confused:



nul
25-02-2005, 10:53
Ich checks nicht,

function resize( )
{
$images = $this->pic;
if ( $this->controlType( $images ) )
{
if ( is_dir( $this->path ) )
{
if ( is_file( $this->path."/".$images ) )
{
$dst_im = $this->target."/".$images;
$src_im = $this->path."/".$images;
$size = getimagesize($src_im);
$dstX = $size[0];
$dstY = $size[1];
$srcX = $size[0];
$srcY = $size[1];
$dstW = $size[0];
$dstH = $size[1];
$srcW = $size[0];
$srcH = $size[1];

echo $dst_im . "<br>\n";
echo $src_im . "<br>\n";
print_r($size);


imagecopy( $dst_im,
$src_im,
$dstX,
$dstY,
$srcX = $size[0],
$srcY = $size[1],
$dstW = $size[0],
$dstH = $size[1],
$srcW = $size[0],
$srcH = $size[1] ); /* 89 */
}
else
{
echo "No image!";
}
}
else
{
echo "Wrong path!";
}
}
}
Ich erhalte die Meldung:

include/desktop/tmp/001-screenshot.png
include/desktop/gnome/001-screenshot.png
Array ( [0] => 1280 [1] => 1024 [2] => 3 [3] => width="1280" height="1024" [bits] => 8 [mime] => image/png )
Warning: Wrong parameter count for imagecopy() in /var/www/include/util/PicResize.php on line 89

Wieso in Zeile 89?
Auch wenn ich andere Werte einsetze hilfts nichts. Das Zielbild $dst_im muss doch nicht existieren, oder? Kann mir jemand sagen was ich da falsch mache?

mfg
nul

Gaert
25-02-2005, 11:01
Hallo,

ein klarer Fall von RTFM und RTFEM ("Read the fucking error message"): http://de2.php.net/manual/en/function.imagecopy.php

Imagecopy hat nun mal nur 8 Parameter und nicht 10.

Und "wieso 89" --> weil der fehlerhafte Aufruf der Funktion in Zeile 89 endet.

Gruß,

Gaert

nul
25-02-2005, 11:22
Das ist heut nicht mein Tag :(
Aber die Fehler hoeren trotzdem nicht auf:

function resize( )
{
$images = $this->pic;

if ( $this->controlType( $images ) )
{
if ( is_dir( $this->path ) )
{
$src_im = $this->path."/".$images;
if ( is_file( $src_im ) )
{
$dst_im = $this->target."/".$images;
$size = getimagesize($src_im);
$dst_x = $size[0];
$dst_y = $size[1];
$src_x = $size[0];
$src_y = $size[1];
$src_w = $size[0];
$src_h = $size[1];

echo $dst_im . "<br>\n";
echo $src_im . "<br>\n";
print_r($size);

imagecopy ( $dst_im,
$src_im,
$dst_x,
$dst_y,
$src_x,
$src_y,
$src_w,
$src_h); /* 84 */
}
else
{
echo "No image!";
}
}
else
{
echo "Wrong path!";
}
}
}
und die Meldung:

include/desktop/tmp/001-screenshot.png
include/desktop/gnome/001-screenshot.png
Array ( [0] => 1280 [1] => 1024 [2] => 3 [3] => width="1280" height="1024" [bits] => 8 [mime] => image/png )
Warning: imagecopy(): supplied argument is not a valid Image resource in /var/www/include/util/PicResize.php on line 84

Gaert
25-02-2005, 13:39
Hallo,

und wieder RTFM...

die ersten beiden Parameter sind keine Dateinamen sondern eine Resource... die bekommst du über die Funktion http://php.net/imagecreatefrompng bzw. http://php.net/imagecreatetruecolor

Gruß,

Gaert

Matflasch
28-02-2005, 18:33
Hi,

ich kann dir meine Funktion wohl anbieten...
Funzt ganz gut bei mir...

Mfg, Matflasch




function mtf_ImgResize($p_Picture, $p_NewPicture, $p_ImageType, $p_SizeInPixel){
// Pfad zum OriginalBild
$OriginalPicture = $p_Picture;
// Pfad zum neuen Bild
$DestPicture = $p_NewPicture;
// Ressource vom Bild
$handle = "";
// OriginalBreite
$OriginalSizeX = "";
// OriginalHoehe
$OriginalSizeY = "";
// Maximale neue Groesse
$MaxSize = "";
// Minimale neue Groesse
$MinSize = "";
// Groesse in Pixel
$SizeInPixel = "";
// Proportionale Rate
$Rate = "";
// Neue Breite
$NewSizeX = "";
// Neue Hoehe
$NewSizeY = "";
// Temporaeres Bild
$TmpPic = "";
// Image Typ
$ImageType = "";


// Wenn die Groesse in Pixel nicht uebergeben
// wurde, wird 100 als Standard gesetzt
if(!isset($p_SizeInPixel)) {
$SizeInPixel = "100";
} else {
$SizeInPixel = $p_SizeInPixel;
}

// ImageTyp
$ImageType = $p_ImageType;

// Entscheiden, welcher Typ es ist und eine
// Ressource ID zum bearbeiten erstellen
// JPEG
if($ImageType == "image/jpeg") {
$handle = @imagecreatefromjpeg($OriginalPicture);
}
// PNG
else if($ImageType == "image/png") {
$handle = @imagecreatefrompng($OriginalPicture);
}
// GIF
else if($ImageType == "image/gif") {
$handle = @imagecreatefromgif($OriginalPicture);
}

// Original Breite
$OriginalSizeX = imagesx($handle);
// Original Hoehe
$OriginalSizeY = imagesy($handle);

// Wenn die Original Breite groesser ist als die Original Hoehe...
if($OriginalSizeX > $OriginalSizeY){
//
$MaxSize = $OriginalSizeX;
$MinSize = $OriginalSizeY;
}
// Wenn die Original Breite kleiner oder gleich der Original Hoehe ist...
if($OriginalSizeX <= $OriginalSizeY){
//
$MaxSize = $OriginalSizeY;
$MinSize = $OriginalSizeX;
}

// Proportionale Rate berechnen
$Rate = $MaxSize / $SizeInPixel;
// Die neue Breite proportional setzen
$NewSizeX = $OriginalSizeX / $Rate;
// Die neue Breite proportional setzen
$NewSizeY = $OriginalSizeY / $Rate;

// Wenn die neue Breite groesser ist als die original Breite...
if($NewSizeX > $OriginalSizeX) {
// werden Breite und Hoehe vom original
// Bild verwendet
$NewSizeX = $OriginalSizeX;
$NewSizeY = $OriginalSizeY;
}

// Die neuen Groessen abrunden
$NewSizeX = ceil($NewSizeX);
$NewSizeY = ceil($NewSizeY);

// Tmp Bild zum resizen erstellen
$TmpPic = imageCreatetruecolor($NewSizeX, $NewSizeY);

// Das Bild resizen
imagecopyresampled($TmpPic, $handle, 0, 0, 0, 0, $NewSizeX, $NewSizeY, $OriginalSizeX, $OriginalSizeY);

// Das Bild zum Zielpfad kopieren
// JPG
if($ImageType == "image/jpeg") {
imagejpeg($TmpPic, $DestPicture, $SizeInPixel);
}
// PNG
else if($ImageType == "image/png") {
imagepng($TmpPic, $DestPicture, $SizeInPixel);
}
// GIF
else if($ImageType == "image/gif") {
imagegif($TmpPic, $DestPicture, $SizeInPixel);
}

// Die Tmp Daten loeschen um den Speicher freizugeben
imagedestroy($handle);
imagedestroy($TmpPic);
}

nul
28-02-2005, 19:03
Hab das jetzt so geloest:

function resize( )
{
$images = $this->pic;

if ( $this->controlType( $images ) )
{
if ( is_dir( $this->path ) )
{
$src_im = $this->path."/".$images;
if ( $this->path == $this->target )
{
$dst_im = $this->target."/tb_".$images;
$this->pic = "tb_".$images;
}
else
{
$dst_im = $this->target."/".$images;
}
if ( is_file( $src_im ) && !is_file($dst_im) && is_dir( $this->target) )
{
$destimg = imagecreate(
$this->width,
$this->hight );
$srcimg = imagecreatefrompng($src_im);
imagecopyresized( $destimg,
$srcimg,
0,
0,
0,
0,
$this->width,
$this->hight,
imagesx($srcimg),
imagesy($srcimg) );
imagepng($destimg,$dst_im);
}
}
else
{
echo "Wrong path!";
}
}
}

Vielen dank fuer eure gedult!