After two days of failure, I announced the failure. please help me !!

Source: Internet
Author: User
Tags transparent color
After two days of failure, I announced the failure. please help me !! The following code directly processes the image as a garden with four corners.
However, the generated image does not generate a file. you can generate a file to be processed in the specified directory ..
After two days, it never works... Please help me .. Thank you!
For example run Web site: http://www.xxx.com/pic.php? Gopic00001234.jpg

The pic. php code is as follows:
 _ Image_path = $ image_path; $ this-> _ radius = $ radius; $ this-> _ r = (int) $ r; $ this-> _ g = (int) $ g; $ this-> _ B = (int) $ B;} private function _ get_lt_rounder_corner () {$ radius = $ this-> _ radius; $ img = imagecreatetruecolor ($ radius, $ radius); $ bgcolor = imagecolorallocate ($ img, $ this-> _ r, $ this-> _ g, $ this-> _ B); $ fgcolor = imagecolorallocate ($ img, 0, 0, 0); imagefill ($ img, 0, 0, $ bgcolor); imagefilledarc ($ I Mg, $ radius * 2, $ radius * 2,180,270, $ fgcolor, IMG_ARC_PIE); imagecolortransparent ($ img, $ fgcolor); return $ img ;} private function _ load_source_image () {$ ext = substr ($ this-> _ image_path, strrpos ($ this-> _ image_path ,'. '); if (empty ($ ext) {return false;} switch (strtolower ($ ext) {case '.jpg ': $ img = @ imagecreatefromjpeg ($ this-> _ image_path); break; case '.gif ': $ img = @ imagecr Eatefromgif ($ this-> _ image_path); break; case '.png ': $ img = @ imagecreatefrompng ($ this-> _ image_path); break; default: return false ;} return $ img;} public function round_it () {// load the source image $ src_image = $ this-> _ load_source_image (); if ($ src_image = false) {die ('Error: image does not exist');} $ image_width = imagesx ($ src_image); $ image_height = imagesy ($ src_image); // create a new image, with src_widt H, src_height, and fill it with transparent color $ image = imagecreatetruecolor ($ image_width, $ image_height); $ trans_color = imagecolorallocate ($ image, $ this-> _ r, $ this-> _ g, $ this-> _ B); imagefill ($ image, 0, 0, $ trans_color ); // then overwirte the source image to the new created image imagecopymerge ($ image, $ src_image, 0, 0, 0, 0, $ image_width, $ image_height, 100 ); // then just copy all the rounded Corner images to the 4 corners $ radius = $ this-> _ radius; // lt $ lt_corner = $ this-> _ get_lt_rounder_corner (); imagecopymerge ($ image, $ lt_corner, 0, 0, 0, 0, $ radius, $ radius, 100); // lb $ lb_corner = imagerotate ($ lt_corner, 90, $ trans_color); imagecopymerge ($ image, $ lb_corner, 0, $ image_height-$ radius, 0, 0, $ radius, $ radius, 100); // rb $ rb_corner = imagerotate ($ lt_corner, 180, $ trans_color); I Magecopymerge ($ image, $ rb_corner, $ image_width-$ radius, $ image_height-$ radius, 0, 0, $ radius, $ radius, 100 ); // rt $ rt_corner = imagerotate ($ lt_corner, 270, $ trans_color); imagecopymerge ($ image, $ rt_corner, $ image_width-$ radius, 0, 0, 0, $ radius, $ radius, 100); // set the transparency imagecolortransparent ($ image, $ trans_color); // display it header ('content-Type: image/png '); imagepng ($ imag E); imagedestroy ($ src_image); imagedestroy ($ image); imagedestroy ($ lt_corner); imagedestroy ($ lb_corner); imagedestroy ($ rb_corner ); imagedestroy ($ rt_corner) ;}$ rounder = new RoundedCorner ($ _ GET ['gopic '], 20); $ rounder-> round_it ();?>


Reply to discussion (solution)

Dude, please use saveas () to save the image so that it can be placed in the specified directory.

This post was last edited by xuzuning at 19:07:04

Public function round_it ($ filename = ''){
....
Header ('content-Type: image/png ');
If ($ filename) imagepng ($ image, $ filename );
Else imagepng ($ image );
Imagedestroy ($ src_image );
Imagedestroy ($ image );
Imagedestroy ($ lt_corner );
Imagedestroy ($ lb_corner );
Imagedestroy ($ rb_corner );
Imagedestroy ($ rt_corner );
}

Public function round_it ($ filename = ''){
....
Header ('content-Type: image/png ');
If ($ filename) imagepng ($ image, $ filename );
Else imagepng ($ image );
Imagedestroy ($ src_image );
Imagedestroy ($ image );
Imagedestroy ($ lt_corner );
Imagedestroy ($ lb_corner );
Imagedestroy ($ rb_corner );
Imagedestroy ($ rt_corner );
}

Moderator .. Are you replacing this? I can't do it ..
Can you just give me a complete one?

Dude, please use saveas () to save the image so that it can be placed in the specified directory.
I know how to write specific code? Let's take a look .. I can't do it anymore ..

Images cannot be saved in directories.

Public function round_it ($ filename = ''){
....
Header ('content-Type: image/png ');
If ($ filename) imagepng ($ image, $ filename );
Else imagepng ($ image );
Imagedestroy ($ src_image );
Imagedestroy ($ image );
Imagedestroy ($ lt_corner );
Imagedestroy ($ lb_corner );
Imagedestroy ($ rb_corner );
Imagedestroy ($ rt_corner );
}

Use the moderator's modifications.
$ Rounder-> round_it (the directory you want to save );

Set
Imagepng ($ image );
Change
Imagepng ($ image, $ src_image );
Try

The above error should be changed
Imagepng ($ image );
Change
Imagepng ($ image, $ this-> _ image_path );
Incorrect

You only need
Imagepng ($ image );
Change
Imagepng ($ image, $ this-> _ image_path );
Okay.
Do not change anything else

You only need
Imagepng ($ image );
Change
Imagepng ($ image, $ this-> _ image_path );
Okay.
Do not change anything else

I tried not to display the images.
Or is my code wrong? Can you paste the correct information between moderators for me?
Otherwise, my code may also be wrong ??


Public function round_it ($ filename = ''){
....
Header ('content-Type: image/png ');
If ($ filename) imagepng ($ image, $ filename );
Else imagepng ($ image );
Imagedestroy ($ src_image );
Imagedestroy ($ image );
Imagedestroy ($ lt_corner );
Imagedestroy ($ lb_corner );
Imagedestroy ($ rb_corner );
Imagedestroy ($ rt_corner );
}

Use the moderator's modifications.
$ Rounder-> round_it (the directory you want to save );

And I am confused .. Please paste the code directly .. Thank you!

No one helped?
As you said, I can't do anything else...


You only need
Imagepng ($ image );
Change
Imagepng ($ image, $ this-> _ image_path );
Okay.
Do not change anything else

I tried not to display the images.
Or is my code wrong? Can you paste the correct information between moderators for me?
Otherwise, my code may also be wrong ??

No. I tested it.


This is the image I used before using your program.

Below is the picture after your program is used

Inverted. two figures are reversed.

The first one is handled by your program.
The one below is the source image.

Inverted. two figures are reversed.

The first one is handled by your program.
The one below is the source image.
I tried it... Will the code above give me an error ???
You can paste the code directly .. Isn't it okay for me to fool you? I can't use it...
Paste it and paste it ..

Bool imagepng (resource image [, string filename])

Imagepng () outputs the GD image stream (image) in PNG format to the standard output (usually in a browser), or outputs the file name to the file if filename is used.


Inverted. two figures are reversed.

The first one is handled by your program.
The one below is the source image.
I tried it... Will the code above give me an error ???
You can paste the code directly .. Isn't it okay for me to fool you? I can't use it...
Paste it and paste it ..

I directly changed imagepng ($ image); to imagepng ($ image, $ this-> _ image_path );

None of them have been changed.

Oh, it is worth noting that, because you have not copied or moved (uploaded) this program to another folder, the generated rounded corner Image overwrites the original image.

If you want to generate a file in another folder without damaging the original image, you must first copy and move the file (that is, upload) to another folder (the folder you specified ), then, use the moved file to process the rounded corner.

Oh, it is worth noting that, because you have not copied or moved (uploaded) this program to another folder, the generated rounded corner Image overwrites the original image.
How can I write the output name file?

Oh, it is worth noting that, because you have not copied or moved (uploaded) this program to another folder, the generated rounded corner Image overwrites the original image.
It's speechless! I tell you, I changed imagepng ($ image) directly to imagepng ($ image, $ this-> _ image_path) based on your method ); no !!!!!!!!
Have you tried it yourself ???????


Oh, it is worth noting that, because you have not copied or moved (uploaded) this program to another folder, the generated rounded corner Image overwrites the original image.
It's speechless! I tell you, I changed imagepng ($ image) directly to imagepng ($ image, $ this-> _ image_path) based on your method ); no !!!!!!!!
Have you tried it yourself ???????
Speechless. how can I find the two images?


Before processing
Programs used

Execution result


Result after processing:


Before processing
Programs used

Execution result


Result after processing:


I can conclude that you must tell me where to change the code?
I changed this sentence according to what you said !!!!!
After the modification, not only will the file not be generated, but the image cannot be displayed! You see:

If you want to generate a file in another folder without damaging the original image, you must first copy and move the file (that is, upload) to another folder (the folder you specified ), then, use the moved file to process the rounded corner.

Sorry .. Yes !!! It's actually a problem with my computer !!!!!
I just need to change my computer !!! Speechless... It's really hard for you to moderator !!!

For another question, if you want to save the generated image output to a specified directory, how can you write it?


If you want to generate a file in another folder without damaging the original image, you must first copy and move the file (that is, upload) to another folder (the folder you specified ), then, use the moved file to process the rounded corner.

Sorry .. Yes !!! It's actually a problem with my computer !!!!!
I just need to change my computer !!! Speechless... It's really hard for you to moderator !!!

For another question, if you want to save the generated image output to a specified directory, how can you write it?

I mentioned this at 20 #.
"If you want to generate a file in another folder without damaging the original image, you must first copy and move the file (that is, upload) to another folder (the folder you specified ), then use the moved file to process the rounded corner"

If you want to generate a file in another folder without damaging the original image, you must first copy and move the file (that is, upload) to another folder (the folder you specified ), then, use the moved file to process the rounded corner.
Isn't that a problem?
Can't I say www.xxx.com/pic.php? In this way, the picture123.jpg file is executed to generate a file to the specified directory?


If you want to generate a file in another folder without damaging the original image, you must first copy and move the file (that is, upload) to another folder (the folder you specified ), then, use the moved file to process the rounded corner.
Isn't that a problem?
Can't I say www.xxx.com/pic.php? In this way, the picture123.jpg file is executed to generate a file to the specified directory?

Dizzy, of course.

Why can't I copy and move files?

The key is that you need to write a file copy mobile program.

If you use the original image name when saving the image, add a random number when saving the image. Otherwise, the generated image is still the original image.

Or change the name when saving.

The key is that you need to write a file copy mobile program.
Can I rename the file? For example, save the generated file to the okpic directory .. I tried it tonight... The code is always written incorrectly ....
How can I continue to ask for help?


The key is that you need to write a file copy mobile program.
Can I rename the file? For example, save the generated file to the okpic directory .. I tried it tonight... The code is always written incorrectly ....
How can I continue to ask for help?
I want to ask you, do you know how to copy and move files?

Simple cannot be simpler

As long
Private function _ load_source_image (){
This function
$ Ext = substr ($ this-> _ image_path, strrpos ($ this-> _ image_path ,'.'));
If (empty ($ ext )){
Return false;
}
In this code, add a copy code to copy the mobile file. that is:

if (file_exists($this->_image_path) === TRUE) { if(!file_exists('okpic')){  @mkdir('okpic'); } $newpath='okpic/'.$this->_image_path;  if (!copy($this->_image_path, $newpath)){   return false;  }  $this->_image_path=$newpath; }


It's just such a simple copy and move.

Easy to rename

Is as long
$ Newpath = 'okpic/'. $ this-> _ image_path;
Change
$ Newpath = 'okpic/'. date ('ymdhis'). $ ext;
In this way, you can rename and copy and move it.

What I said on the second floor is usable.

Easy to rename

Is as long
$ Newpath = 'okpic/'. $ this-> _ image_path;
Change
$ Newpath = 'okpic/'. date ('ymdhis'). $ ext;
In this way, you can rename and copy and move it.
After renaming, I wrote it myself, that is, naming by date.
Now there is a problem, is http://www.xxx.com/pic.php? Gopic = uploadfiles/123.jpg
In this case, when the path directory of uploadfiles is added, the system always prompts that the image does not exist, but a file is generated to okpic?
Where is the code going wrong?

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.