Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
499 views
in Technique[技术] by (71.8m points)

php - how to crop image in codeigniter?

i'm using codeigniter to build a project and right now i need to create a thumb depending on user choice. like he will give me X1,Y1,X2,Y2,X3,Y3,X4,Y4 i want to crop the image depending on that 4 points. i checked the image manipulation class. the crop function seems to be very strange. any help please ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You will need to set the x-axis (left), width (right), y-axis (top), and height (bottom). You need to be sure to set the width and height of the image.

        list($width, $height, $type, $attr) = getimagesize($img);

        $CI->load->library('image_lib');

        $config['image_library'] = 'gd2';
        $config['source_image'] = $img;
        $config['x_axis'] = '10';
        $config['y_axis'] = '10';
        $config['maintain_ratio'] = FALSE;
        $config['width'] = $width-10;
        $config['height'] = $height-10;

The code above will crop the image by 10 pixels on the left, right, top, and bottom. you can feel free to change the value of '10' to whichever value you prefer ;)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...