Avatar billede gedekid Nybegynder
03. august 2011 - 11:55 Der er 6 kommentarer og
1 løsning

php genereret billede i img src bliver ikke vist

Hej eksperter,

i forlængelse med mit spørgsmål http://www.eksperten.dk/spm/944234 vil jeg høre om der er en der kan hjælpe med at løse mit lille problem.

Jeg bruger denne til at vise et valg på et genereret billede uden at godkende det:

onclick="changeImg('preview', 'img.php?room='. $_GET["room"] .'&floor='. $_GET["floor"] .'&wall='. $row["color"] .'"

til at skifte et billede uden reload og min img ser sådan ud:

<img src="img.php?room='. $_GET["room"] .'&floor='. $_GET["floor"] .'&wall='. $_GET["wall"] .'" alt="" id="preview">

men billedet bliver ikke vist. Der kommer kun det velkendte røde kryds.

Min img.php ser således ud:

<?php
header("Content-type: image/jpeg");

define("INCLUDE_DIR", "includes/classes");

/* Autoload classes when used */
function __autoload($class_name) {
  include(INCLUDE_DIR.'/class.'. strtolower($class_name) . '.php');
}

/**********************************************
* Check whether a fullsize image have been
* chosen.
*
* $fullSize        | $_GET is either true or false
* $theXSize        | The width of the image
* $theYSize        | The height of the image
***********************************************/
if(isset($_GET["fs"]) ? $fullSize = $_GET["fs"] : $fullSize = false);

/* Checks if fullsize is true and if it is,
-full will be inserted in the final filename */

if($fullSize == true) {
    $theXSize     = 1024;
    $theYSize    = 768;
} else {
    $theXSize     = 700;
    $theYSize    = 700/960*$theXSize;
}

$img = new ImageGenerator();
$img->imageBuilder($_GET["room"], $_GET["floor"], $_GET["wall"], "couch", "dk", $theXSize, $theYSize, $fullSize, false);
?>

og min ImageGenerator ser således ud:

<?php
class ImageGenerator extends Main {
   
    var $width;
    var $height;
    var $quality = 100;
    var $fileName = "";
   
    /*******************************************************************************
    * This is the imagebuilder function that builds the image
    * based on different userselections
    *
    * $fullFileName        | The filename of the image with entire path
    * $theRoom             | The selected room.
    * $theFloor            | The selected floor
    * $theWall             | The selected wallpaper
    * $theEnvi            | The selected furnitures
    * $theLang             | The language from $_GET
    * $theXSize            | The width of the final image
    * $theYSize            | The height of the final image
    * $fullSize         | Bool value - If the generated image is fullsize or not
    *                      - true or false - true is the fullsize image in new window
    *******************************************************************************/

    function imageBuilder($theRoom, $theFloor, $theWall, $theEnvi = "blank", $theLang, $theXSize, $theYSize, $fullSize) {
       
        $quality = 100; //Final image quality
        $theW = $theXSize; //The width of final image
        $theH = $theYSize; //The height of final image
       
        /*** Beginning of language variabels ***/
       
        $dateLabel = Main::langLabels($theLang, "date") .": ";
        $roomLabel = Main::langLabels($theLang, "room") .": ";
               
        /*** The path of the selected room ***/
        $thePath = "rooms/".$theRoom."";

        /*** The filename of the generated image ***/
        if($fullSize == true) {
            $theImageFileName = "generatedImages/room-". $theRoom ."_floor-". $theFloor ."_wall-". $theWall ."_envi-". $theEnvi ."_".$theLang."-full.jpg";
        } else {
            $theImageFileName = "generatedImages/room-". $theRoom ."_floor-". $theFloor ."_wall-". $theWall ."_envi-". $theEnvi ."_".$theLang.".jpg";
        }
               
        /*** Check if the default background exists ***/
        if(file_exists($thePath."/bg.png")) {
            $theBackgroundImage = imagecreatefrompng($thePath."/bg.png");
            $theSourceImagesXSize = imagesx($theBackgroundImage);
            $theSourceImagesYSize = imagesy($theBackgroundImage);
        }
       
        /*******************************************************
        * Here the selected floor are placed onto the image
        ********************************************************/
        $theFloor = $theFloor;
       
        if (file_exists($thePath."/floors/".$theFloor.".png")) {
            $createFromThis = $thePath."/floors/".$theFloor.".png";
        } else {
              $createFromThis = $thePath."/blank.png";
        }
       
        $theFloorImage = imagecreatefrompng($createFromThis);
       
        imagecopy($theBackgroundImage,$theFloorImage,0,0,0,0,$theSourceImagesXSize,$theSourceImagesYSize);
       
        imagejpeg($theFloorImage, $theImageFileName, $quality);
        imagedestroy($theFloorImage);
       
        /*******************************************************
        * Here the selected wallpaper are placed onto the image
        ********************************************************/
        $theWall = $theWall;
   
        if (file_exists($thePath."/walls/".$theWall.".png")) {
            $createFromThis = $thePath."/walls/".$theWall.".png";
        } else {
            $createFromThis = $thePath."/walls/blank.png";
        }
         
        $theWallImage = imagecreatefrompng($createFromThis);
        imagecopy($theBackgroundImage,$theWallImage,0,0,0,0,$theSourceImagesXSize,$theSourceImagesYSize);
        imagedestroy($theWallImage);
       
        /*******************************************************
        * Here the selected furnitures are placed onto the image
        ********************************************************/
        $theEnvi = $theEnvi;
   
        if (file_exists($thePath."/furnitures/".$theEnvi.".png")) {
            $createFromThis = $thePath."/furnitures/".$theEnvi.".png";
        } else {
            $createFromThis = $thePath."/furnitures/blank.png";
        }
         
        $theEnviImage = imagecreatefrompng($createFromThis);
        imagecopy($theBackgroundImage,$theEnviImage,0,0,0,0,$theSourceImagesXSize,$theSourceImagesYSize);
        imagedestroy($theEnviImage);
       
        /*******************************************************
        * Here the logo are printed onto the image
        *
        * $theLogo        | The path of the logo
        * $theLogoX        | Finds the width of the logo
        * $theLogoY        | Finds the height of the logo
        ********************************************************/
        $theLogo = imagecreatefrompng("logo_trans.png");
        $theLogoX = imagesx($theLogo);
        $theLogoY = imagesy($theLogo);
        imagecopy($theBackgroundImage,$theLogo,10,10,0,0,$theLogoX,$theLogoY);
        imagedestroy($theLogo);
       
        /*******************************************************
        * At this stage in the image creation a box is
        * generated and placed at the bottom of the image.
        * In that box the date are written in the right side
        * In the left side the different selections are written
        ********************************************************/
        $selectionTxt = Main::langLabels($theLang, "room").": ". Main::langLabels($theLang, $theRoom) ." | ". Main::langLabels($theLang, "wall").": ". $theWall ." | ". Main::langLabels($theLang, "environment").": ". $theEnvi;
        $dateTxt = Main::langLabels($theLang, "date").": ". date("d-m-Y");
       
        imagefilledrectangle($theBackgroundImage, 0, 940, 1280, 960, imagecolorallocatealpha($theBackgroundImage, 0,0,0, 60));       
        imagettftext($theBackgroundImage, 8, 0, 1172, 953, imagecolorallocate($theBackgroundImage, 209,198, 140), "verdana.ttf", $dateTxt);
        imagettftext($theBackgroundImage, 8, 0, 20, 953, imagecolorallocate($theBackgroundImage, 209,198, 140), "verdana.ttf", $selectionTxt);
       
        /*******************************************************
        * Here the final image is generated based on
        * width and height defined in top of this script
        *
        * $theDestionationImage        | The final image
        * $theBackgroundImage        | The total images with all
        *                               the layers combined
        ********************************************************/
        $theDestinationImage = imagecreatetruecolor($theW,$theH);
        imagecopyresampled($theDestinationImage,$theBackgroundImage,0,0,0,0,$theW,$theH,$theSourceImagesXSize,$theSourceImagesYSize);
        imagealphablending($theDestinationImage, true);
       
        /*******************************************************
        * Output the final image and clear the memory
        ********************************************************/
        imagejpeg($theDestinationImage, $theImageFileName, $quality);               
               
        imagedestroy($theDestinationImage);
        return;
    }
}
?>
Avatar billede majbom Novice
03. august 2011 - 12:40 #1
du viser heller ikke billedet, du gemmer det kun som en fil...
Avatar billede gedekid Nybegynder
03. august 2011 - 13:06 #2
Arh... Forgive my stupidity!! Når der trykkes "Vis farve" så genererer den billedet! Så billedet er allerede gemt!

Så jeg ændrede
<img src="img.php?room='. $_GET["room"] .'&floor='. $_GET["floor"] .'&wall='. $_GET["wall"] .'" alt="" id="preview">

til <img src="generatedImages/genereret-fil-navn.jpg"> og så kører det!

Vil du smide et svar, da din kommentar ledte mig på rette spor :)
Avatar billede gedekid Nybegynder
03. august 2011 - 13:35 #3
Arh.. jeg var lige hurtig nok! Nu genererer den ikke billedet!
Avatar billede majbom Novice
03. august 2011 - 14:09 #4
har du en mappe der hedder "generatedImages" hvor der er skriverettigheder på?
Avatar billede gedekid Nybegynder
03. august 2011 - 15:11 #5
Jeg fik den til at du' med lidt flytten rundt :) Smider du lige et svar?
Avatar billede majbom Novice
03. august 2011 - 15:32 #6
super :)
Avatar billede majbom Novice
04. august 2011 - 16:14 #7
tfp :)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester