Imagecopyresized -- Copy and resize part of an image
Description
Int imagecopyresized (resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int DTH, int srcW, int srcH)
Imagecopyresized () copies a rectangular portion of one image to another image. dst_im is the destination image, src_im is the source image identifier. if the source and destination coordinates and width and heights differ, appropriate stretching or shrinking of the image fragment will be Med. the coordinates refer to the upper left corner. this function can be used to copy regions within the same image (if dst_im is the same as src_im) but if the regions overlap the results will be unpredictable.
See also imagecopyresampled ().
User Contributed Notes
Imagecopyresized
Plusplus7@hotmail.com
25-Sep-1999
Saw this one on the ng and it works fine-just trying to figure it out
Jpg.
If you want to resize or copy an image from or to a datbase, just use
Temp-file as buffer. E. g.: copy all the image-data from the database to
Tempfile, use the resize-function on another tempfile and copy all
Data from to tempfile back into the database.
Skurrilo@skurrilo.de
28-Nov-2000
If you aren't happy with the quality of the resized images, just give
ImageMagick a try. (http://www.imagemagick.org) This is
A commandline tool for converting and viewing images.
Jernberg@fairytale.se
15-Feb-2001 07:02
[Ed. note: if you're using GD 2.x, you can use imagecopyresampled () which
Does exactly the same thing]
Here is my addition to imagecopyresized
It implements bicubic interpolation of pixels so the result is much better
Than the ordinary imagecopyresized...
Copy it into the src/ext/gd/gc. c and recompile the lib.
I wish someone cocould do that so it's stored in the "official"
Release
It's a really good function to scale down pictures to thumbnails.
/* {Proto int imagecopyresizedbicubic (int dst_im, int src_im, int
Dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w,
Int src_h)
Copy and resize part of an image */
PHP_FUNCTION (imagecopyresizedbicubic)
{
Zval ** SIM, ** DIM, ** SX, ** SY, ** SW, ** SH, ** DX, ** DY, ** DW, ** DH;
GdImagePtr im_dst, im_src;
Int srcH, srcW, DTH, dstW, srcY, srcX, dstY, dstX;
Int I, j;
Int r, g, B, c1, c2, c3, c4, color;
Float sX, sY;
Float scaleX, scaleY, scaleX2, scaleY2;
GDLS_FETCH ();
R = (im_src-> red [c1] + im_src-> red [c2] + im_src-> red [c3] +
Im_src-> red [c4])/4;
G = (im_src-> green [c1] + im_src-> green [c2] + im_src-> green [c3]
+ Im_src-> green [c4])/4;
B = (im_src-> blue [c1] + im_src-> blue [c2] + im_src-> blue [c3] +
Im_src-> blue [c4])/4;
Color = gdImageColorClosest (im_dst, r, g, B );
GdImageSetPixel (im_dst, (I + dstX), (j + dstY), color );
};
};
RETURN_TRUE;
}
# Endif/* HAVE_LIBGD */
Aleczapka@gmx.net
13-Mar-2001 :33
Re: imagecopyresizedbicubic
Yes, this function is really great! The thumbnails are much, much better.
However the example posted abve is for PHP4, and if you need it for PHP3
(And you really shocould use it), you have to do the following:
(Notice: I changed the name of this function to imagecopyresizedbb-it's
Just shorter to write this way)
Edit the file functions/gd. c.
Find the function named "function_entry gd_functions []" and add
This function definition there: (I suggest below the orginal
Imagecopyresized-around line 98)
Then add this function (I suggest below the orginal imagecopyresized
Function-around line 2030)
/* {Proto int imagecopyresizedbb (int dst_im, int src_im, int dst_x, int
Dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h );
Copy and resize (bicubic) part of an image */
Void php3_imagecopyresizedbb (INTERNAL_FUNCTION_PARAMETERS)
{
Pval * SIM, * DIM, * SX, * SY, * SW, * SH, * DX, * DY, * DW, * DH;
GdImagePtr im_dst;
GdImagePtr im_src;
Int srcH, srcW, DTH, dstW, srcY, srcX, dstY, dstX;
Int ind_type;
Int I, j;
Int r, g, B, c1, c2, c3, c4, color;
Float sX, sY;
Float scaleX, scaleY, scaleX2, scaleY2;
GD_TLS_VARS;
R = (im_src-> red [c1] + im_src-> red [c2] +
Im_src-> red [c3] + im_src-> red [c4])/4;
G = (im_src-> green [c1] + im_src-> green [c2] +
Im_src-> green [c3] + im_src-> green [c4])/4;
B = (im_src-> blue [c1] + im_src-> blue [c2] +
Im_src-> blue [c3] + im_src-> blue [c4])/4;
Color = gdImageColorClosest (im_dst, r, g, B );
GdImageSetPixel (im_dst, (I + dstX), (j + dstY), color );
};
};
RETURN_TRUE;
}
/*}}}*/
Then add this line in functions/php3_gd.h (I suggest below the orginal
Imagecopyresized function-around line 74)
Then recompile PHP and that's it!
Later in PHP script just use imagecopyresizedbb instead of standard
Imagecopyresized function and your thumbnails will become smooth and
Shiny.
Colin_Witt@baylor.edu
05-Apr-2001
One note on getting the ImageCopyResizedBicubic to work. Just adding
Code block to gd. c won't do it. You have to do two other things as well:
In the first 150 or so lines of gd. c, you will find a section that starts
Like this:
Function_entry gd_functions []
Find the line that starts PHP_FE (imagecopyresized, copy this line, and
Paste a new copy below the original. Change
"Imagecopyresized" to "imagecopyresizedbicubic" in
New copy.
Also, you will need to edit php_gd.h as follows:
Find the line that says:
PHP_FUNCTION (imagecopyresized );
(It was line 87 for me)
And add a line below it that says:
PHP_FUNCTION (imagecopyresizedbicubic );
Once you 've made these changes, recompile and reinstall php, and you
Shocould be good to go. Scaling works much better with this function.
Aleczapka@gmx.net
05-Apr-2001
Just wanted to point out that the post above applies to PHP4. As well
The one posted, 3 posts abve, concerning
"Imagecopyresizedbicubic ".
If you wowould like to use it with PHP3, read the post titled "re:
Imagecopyresizedbicubic ".
Darren@php4hosting.com
16-Jun-2001
OK after too then e-mails :)
Http://www.alt-php-faq.org/downloads/patch
Assuming you are using Linux & PHP-4.0.5 Source
Get PHP-4.0.5 Source
Wget http://www.alt-php-faq.org/downloads/patch
Tar-pxzf php-4.0.5.tar.gz
Cd php-4.0.5
Patch-p0 <../patch
Then do your normal configure/make install
Check PHPinfo under GD for ImageResizeBicubic enabled.
Sfm15@columbia.edu
05-Jul-2001
I 've been using the imagecopyresizedbicubic function and it works great
Making higher quality thumbnails. However, it seems that the thumbnails
Are very large with respect to memory. For instance, I'm resizing images
From 200x280 pixels to 140x195 pixels but the smaller pictures wind up
Being about 26 K while the original larger pictures are usually around 12 K.
Also, when I output the image as a JPEG, it makes no difference what I
Select as the quality. It comes out being the same size/quality
Regardless.
Rze@counter-strike.net
10-Jul-2001 11: 47
For those who can't update their GD modules, I 've made this function. If
You think you can make any good changes, feel free to e-mail them to me.
Frankly I have no idea what the for loop in the first example does, I just
Guessed and it seems to work fine.
Note: it's a VERY, VERY, VERY slow function. Never use it for dynamic
Output, only saving to a thumbnail file or the like.
Function ImageCopyResampleBicubic ($ dst_img, $ src_img, $ dst_x, $ dst_y,
$ Src_x, $ src_y, $ dst_w, $ dst_h, $ src_w, $ src_h)
/*
Port to PHP by John Jenkins July 10 2001 -- original code (in C, for
Php gd Module by jernberg@fairytale.se
*/
{
For ($ I = 0; $ I <256; $ I ++) {// get pallete. Is this algoritm
Correct?
$ Colors = ImageColorsForIndex ($ src_img, $ I );
ImageColorAllocate ($ dst_img, $ colors ['red'], $ colors ['green'],
$ Colors ['blue']);
}
Works only if the colordepth of the png-file is true color. I have tried
It with 256 colors and the picture was just black.
28--200-2001
When using this function along with imagecreatefromstring () you must use
ImageCreateTrueColor () for the destination image. This will give
Complete palette. Otherwise, the resulting image will look strange. This
Also applies to ImageCopyResampled ().
William@waw.com.br
12-Jan-2002
REDEFINE? BICUBIC? ARGH!
If you aren't happy with the quality of the resized images, just use this:
// Cria thumbnail de uma imagem, com boa qualidade
//-----------------------------------------------
// William G. Comnisky
// William@waw.com.br
If you aren't happy with the quality of the resized images, just use this:
* Code *"
Bicubic is better than resampled. Both are not great looking, but bicubic
IS better looking.
In either case, resampled is only on GD 2.0. Most servers don't have 2.0
And I'm not even sure if bicubic works with 2.0.
Big_dog001@hotmail.com
03-Apr-2002
Regarding the bicubic function. I hand patched with all the notes above on
Php 4.1.2 on openbsd 2.8 with apache 1.3.12 and was getting errors in
Apache log file like:
Undefined symbol "_ GDLS_FETCH" called from [the libphp4.so]...
By removing the "GDLS_FETCH ()" in the suggested bicubic function
It started working on openbsd with no problems.
Not sure what this GDLS_FETCH function is but it wasn' t supported on
Openbsd ....
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.