THINKPHP + JS implement scaling image screenshot

Source: Internet
Author: User
Upload image -- save and display image -- JS get thumbnail parameter -- submit location parameter -- image scaling save class process image -- save captured image -- Update database -- jump

Upload image -- save and display image -- JS get thumbnail parameter -- submit location parameter -- image scaling save class process image -- save captured image -- Update database -- jump

Author: Yang xinqi

Original link:

A big brother of the TP Forum joined me tonight and said that he also encountered this problem! Think about the fact that many things have been encountered. Should we share them? In fact, many of my own things come from other people, and they are used by the network! It can be improved only when you share more information!

Implementation Method

Upload image -- save and display image -- JS get thumbnail parameter -- submit location parameter -- image scaling save class process image -- save captured image -- Update database -- jump

Several images

The following are examples

Main Implementation Code
The Code is as follows:
Public function cutimg ()
{
$ Result = $ this-> upload ('temp ');
If (! Is_array ($ result ))
{
$ This-> redirect ('index ');
}
Else
{
$ This-> assign ('imgurl', '/'. C ('attachdir'). '/temp/'. $ result [0] ['savename']);
$ This-> assign ('imgname', $ result [0] ['savename']);
$ This-> display ();
}
}

The Code is as follows:
Public function setavatar ()
{
If (! Empty ($ _ REQUEST ['cut _ pos'])
{
// Import ('org. Util. ImageResize ');
Require ('imageresize. class. php ');
$ Imgresize = new ImageResize ();
// Use the full path
$ Url = C ('attachdir'). '/temp/'. trim ($ _ POST ['imgname']);
$ Imgresize-> load ($ url );
Dump ($ url );
$ Posary = explode (',', $ _ REQUEST ['cut _ pos']);
Foreach ($ posary as $ k => $ v)

$ Posary [$ k] = intval ($ v );

If ($ posary [2]> 0 & $ posary [3]> 0) $ imgresize-> resize ($ posary [2], $ posary [3]);

Dump ($ posary );
// Create filename rule
$ Uico = time (). '.jpg ';
Dump ($ uico );
$ Path = C ('Avatar ');
// Save 120*120 image
$ Imgresize-> cut (120,120, intval ($ posary [0]), intval ($ posary [1]);
$ Large = 'l _ '. $ uico;
$ Imgresize-> save ($ path. $ large );

Echo '';
// Update database
}
Else
{
// Error reporting
}
}

Source code: others to improve themselves, run the TP framework need to visit the http://www.thinkphp1.cn download, and then download the extension package, because the use of Upload class!

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.