Marek Kilimajer wrote:
If I resized the image to 100,611x100,611, cropped it to 100,000, and then resized it to 100x100 it would achieve the effect I want. It's very difficult for me to explain, but I'll try.Chris wrote --- napísal::
Hi there, I've looked in many places but have not found any clues on how to work around this problem.
I'm using imagecopyresampled to resize an image and crop part of it at the same time. The area I need to crop, unfortunately, is sometimes a float, which leads to my problem. imagecopyresampled does not accept float values, and interpolate the images. (Well, technically it accepts them, but just converts them to an integer internally)
The source image is 63x63 pixels ($rImg1). The destination image is 100x100 pixels ($rImg2).
I want to resize $rImg1 to 100.611x100.611, and place the center 100x100 square in $rImg2. The theoretical imagecopyresampled call is below.
imagecopyresampled($rImg2, $rImg1, -0.3055, -0.3055, 0, 0, 100.611, 100.611, 63, 63);
I realize the above code is incorrect, but it seemed the best way to illustrate what I'm attempting to accomplish.
Any help would be greatly appreciated, thanks!
Chris
One pixel is the smallest value in images. How do you want your resulting image to look like? You can resize the image to higher resolution, but you will need to create 100611x100611 pixel image, and that's one hell a lot of memory :)
So, what are you trying to achieve?
It's very similar to the interpolation done on the inner pixels. It's taking the values of all pixels that 'touch' the new pixel, and meshing them together, basically, shifting the pixels 0.3055 to the right would overlap old and new pixels partially. I'll try a grayscale example (it's a bit simpler).
If a black pixel overlapped onto a white pixel, I would get the percentage of the white pixel it's covering, then combine that with the percentage of the white pixel not covered by the black pixel). So, if the black pixel was shifter over 0.4 pixels (40%) onto a white pixel I would calculate the new color : $iGrey = ($iBlack*0.40) + ($iWhite*0.60);
If $iBlack and $iWhite contained the brightess value of a color it would look liek this:
$iGrey = (0 * 0.40) + (255 * 0.60); $iGrey = 0 + 153; $iGrey = 153;
If I was overlapping a White on to a black by 0.4 pixels: $iGrey = (255 * 0.40) + (0 * 0.60); $iGrey = 102 + 0; $iGrey = 102;
or two differing shades of grey pixels: $iGrey = (18 * 0.40) + (97 * 0.60); $iGrey = 7.2 + 58.2; $iGrey = 65.4; $iGrey = 65;
imagecopyresampled is already doing something similar when it's resampling an image to a size that is not a multiple of the old size.
I know there are no fractional pixels in images, but when interpolating between two images, fractions of pixels must be taken into account.
I hope I cleared things up...
Chris
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php