PHP picture Specifies white overlay zoom

Source: Internet
Author: User
Tags imagejpeg

Encounter such a demand: the original size, and the size of the white is different, you need to cut out a core image, and then left the picture left and right, forming a picture of another size. In other words, the position of the original in the new picture can be controlled.

Here's the idea: Create a basemap of the specified size, then scale the original image and put it in the bottom picture, which is the picture overlay.

# # # #这里实现的是第二个箭头所示的效果.

(To finish the first arrow effect, please step http://www.cnblogs.com/haodaquan/p/6381636.html)

The following code is available for reference:

<?php/**************************************************************  @Description:   Picture Overlay Demo **  @Author: haodaquan**  @Date:   2016-11-30 12:07:51**  @Last   modified by:   haodaquan**  @Last  Modified time: 2017-02-09  13:59:51*************************************************************/header (' content-type:image/jpeg '); #图片显示 $ bg_width =  $bg _height = 600; #创建真彩色画布并填补灰色 $final _srouce        = imagecreatetruecolor ($BG _width, $BG _height); $background _color = imagecolorallocate ($ final_srouce,255,255,255); #白色底色imagefill ($final _srouce,0,0, $background _color);  #获取覆盖图片   Size 121*75$ source           =  '/Users/haodaquan/Sites/PyWeb/ Coreimage/newimage/new_image.jpg '; $img _source          =  imagecreatefromjpeg ($SOURCe); $info              = getimagesize ($ source); ###################### #1, directly overlay the picture onto the canvas   #前两个数字为画布起始xy坐标, the middle two numbers to cover the starting XY coordinates of the picture, and the last two numbers to indicate the XY length of the overlay image # Imagecopy ($final _srouce, $img _source,30,50,0,0,121,75), #新图宽度留白, height stay white $blank_width  = 30; $blank _ height = 50; #假设宽度优先填满新图, figure # Calculating zoom ratio $new_width  =  $BG _width-2* $blank _width $new _ height =  $info [1]* ($new _width/$info [0]) #2, with scaled overlay   See the bottom function Note imagecopyresampled ($final _srouce, $img _source, $blank _width, $blank _height,0,0, $new _width, $new _height, $info [0], $info [1]); ###################### imagejpeg ($final _srouce,  './tmp/final_srouce.jpeg ', +); #生成图片   The third parameter is quality [1-100]imagejpeg ($final _srouce );  #页面显示图片 # Destruction of resources Imagedestroy ($final _srouce); Imagedestroy ($img _source);// bool imagecopyresampled   ( resource  $dst _image , resource  $src _image , int  $dst _x   int  $DST _y , int  $src _x , int  $src _y , int  $dst _w , int  $dst _h   int  $src _w , int  $src _h )//  $dst _image: New picture//  $SRC _image: Images required to load//   $DST _x: Sets the x-coordinate//  of the image that needs to be loaded in the new diagram $DST _y: Sets the y-coordinate of the picture to be loaded in the new diagram//  $SRC _x: Sets the area x coordinates to load for loading the image//  $src _ Y: Sets the area y-coordinate to load the picture to load//  $dst _w: Sets the width of the original image to be loaded (scaled in this setting)//  $DST _h: Sets the height of the loaded original (zoom in this setting)//  $src _w: The width of the artwork to load//   $SRC _h: The height of the original image to be loaded

PHP picture Specifies white overlay zoom

Related Article

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.