Search the Community
Showing results for tags 'imagejpeg'.
-
I'm trying to write a script to demenostrate JPG lossy compression. The idea is to start with an image called copy-0000.jpg that is at 100% quality then save it 100 times at 50 quality renaming the copies as it goes. So each copy will be half the quality of the previous. $j = 0; for ($i = 0; $i < 100; $i ++) { $j ++; $fileToCompress = imagecreatefromjpeg('copy-' . sprintf('%04d',$i) . '.jpg'); imagejpeg($fileToCompress, 'copy-' . sprintf('%04d',$j) . '.jpg', 50); imagedestroy($fileToCompress); } But I wind up with 100 copies of the original, each at 50 quality. I am open for ideas.
-
I want to save a caption to a file but for some reason it will not save the file ? here is the code that i am working with ... $directory = "'useruploadedphotos/53346044e7cb6.jpg'"; imagejpeg($jpg_image, $directory);
-
Spent the day trying to figure out why GD library 2.0 imagejpeg($resource_id,NULL,$quality); wouldn't output my images to the browser after updating PHP from 5.3 to 5.4. Allow me to hopefully save you the trouble. If you've enabled GD library and using an external script to generate image files, NO OTHER OUTPUT from the external script is permitted, except the header('Content-Type: image/jpeg'); and the image stream. This goes for any sub include scripts (like a database connection). Error reporting for the executable script should be set to 0 with error_reporting(0); OR you should absolutely make sure none of the scripts are generating any errors or any other output. Here some code: initial_script.php <!DOCTYPE html> <html lang="en"> <head><title>First in stack</title> <meta charset="UTF-8" /> </head> <body> <img src="<?php print createimage.php?imgid=$img_id&uid=$user_id; ?>" alt="red dot" > </body> </html> Next create the image createimage.php <?php include dbconnection.php; //assume db connection and data pull returns image name $image = $row['img_name']; //image create resources etc.. $file="/path/to/".$image; $file_resid = imagecreatefromjpeg($file); // first send the header header('Content-Type: image/jpeg'); // display the image to the browser $quality=100; imagejpeg( $file_resid, NULL, $quality) or die("error displaying jpg"); imagedestroy($image_t); ?> In my case dbconnection.php was spawning a low level notice which was being sent before the header and image stream. This was causing the process to return a broken image icon. Also, imagejpeg now requires NULL if you are displaying the image to the browser. Before (5.3) this parameter could be " ". Firebug was throwing this error - Image corrupt or truncated: