bobdole Posted June 7, 2013 Share Posted June 7, 2013 I'm using a simple script for Image Copy. It's adding an image to the bottom of another image. Both images are the same width. The script works fine, but it changes the color of my images and makes it blurry??? I have no clue why, can anyone help me out Quote <?php $top_file = 'image1.jpg'; $bottom_file = 'image2.jpg'; $top = imagecreatefromjpeg($top_file); $bottom = imagecreatefromjpeg($bottom_file); // get current width/height list($top_width, $top_height) = getimagesize($top_file); list($bottom_width, $bottom_height) = getimagesize($bottom_file); // compute new width/height $new_width = ($top_width > $bottom_width) ? $top_width : $bottom_width; $new_height = $top_height + $bottom_height; // create new image and merge $new = imagecreate($new_width, $new_height); imagecopy($new, $top, 0, 0, 0, 0, $top_width, $top_height); imagecopy($new, $bottom, 0, $top_height+1, 0, 0, $bottom_width, $bottom_height); // save to file imagejpeg($new, 'uploads/merged_image.jpg'); ?> Link to comment https://forums.phpfreaks.com/topic/278886-image-copy-error/ Share on other sites More sharing options...
DaveyK Posted June 7, 2013 Share Posted June 7, 2013 First thing I can think of without really going into your script is that imagejpeg() doesnt provide its third argument, which is quality. By default, the quality is roughly lowered to 75%. You can set it to 100 as well. Link to comment https://forums.phpfreaks.com/topic/278886-image-copy-error/#findComment-1434623 Share on other sites More sharing options...
bobdole Posted June 7, 2013 Author Share Posted June 7, 2013 That's probably it! Thanks, I'm trying it out and trying to learn to use that function correctly. Although that might not be directly it. It changes the image to horrible quality where it is incredibly blurry and an entirely different color. I;m not sure if the difference between 100% and 75% would do that. Link to comment https://forums.phpfreaks.com/topic/278886-image-copy-error/#findComment-1434626 Share on other sites More sharing options...
bobdole Posted June 7, 2013 Author Share Posted June 7, 2013 Alright, the quality was not the problem, but it was a great guess. I'm trying this script now. It works but the image shows up next to each other left to right instead of below the first image. <?php merge('image1.jpg', 'image2.jpg', 'uploads/merged.jpg'); function merge($filename_x, $filename_y, $filename_result) { // Get dimensions for specified images list($width_x, $height_x) = getimagesize($filename_x); list($width_y, $height_y) = getimagesize($filename_y); // Create new image with desired dimensions $image = imagecreatetruecolor($width_x + $width_y, $height_x); // Load images and then copy to destination image $image_x = imagecreatefromjpeg($filename_x); $image_y = imagecreatefromjpeg($filename_y); imagecopy($image, $image_x, 0, 0, 0, 0, $width_x, $height_x); imagecopy($image, $image_y, $width_x, 0, 0, 0, $width_y, $height_y); // Save the resulting image to disk (as JPEG) imagejpeg($image, $filename_result); // Clean up imagedestroy($image); imagedestroy($image_x); imagedestroy($image_y); } ?> Any slight modifications to get this to work? Link to comment https://forums.phpfreaks.com/topic/278886-image-copy-error/#findComment-1434628 Share on other sites More sharing options...
DaveyK Posted June 7, 2013 Share Posted June 7, 2013 http://php.net/manual/en/function.imagecopy.php That should help you. You should look at editing the $dest_y, I THINK. I am not entirely sure tho. Presumably something like this: imagecopy($image, $image_y, 0, $height_x, 0, 0, $width_y, $height_y); Link to comment https://forums.phpfreaks.com/topic/278886-image-copy-error/#findComment-1434632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.