2

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);

    ?>

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

You just solved a problem that took half of my day. THANKYOU!!
why open and read the file you just created when you already have a resource for it in your code?
1

make two lines:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.