Tom Granot
Tom Granot

Reputation: 1850

php gd script not outputting picture correctly

This Code saves the image like it's suppose to, but instead of displaying it as a picture, what is displayed is a line of text inside the picture. help?

<?php

    imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $opacity);


    // print image to screen
    header("content-type: image/jpeg");
    imagejpeg($image, "modified-images/".$codigo2."_modified_picture_status_".$status.".jpg");
    imagedestroy($image);  
    imagedestroy($watermark);

    ?>

Upvotes: 2

Views: 183

Answers (2)

dqhendricks
dqhendricks

Reputation: 19251

make two lines:

// save image
imagejpeg($image, "modified-images/".$codigo2."_modified_picture_status_".$status.".jpg");
// output image
imagejpeg($image);

Upvotes: 1

Manuel Strausz
Manuel Strausz

Reputation: 226

If you are using the second parameter of imagejpeg, the image will not be outputted to the browser but ONLY saved to the file. Try omitting the second parameter if you don't need to save it as a file, and it should output directly to the browser.

If you want to do both, try a print(file_get_contents($imagepath)) after your current block of code. $imagepath should obviously contain the path that you wrote the image to.

Upvotes: 1

Related Questions