Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common image processing methods encapsulated by CI framework

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shows you what the common image processing methods encapsulated in the CI framework are, which are concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

In fact, Wechat mobile phone on the picture, the list had better be a thumbnail, save traffic, this is not, and was a mobile trick, the phone bill signed a point to stop, traffic less than 90 yuan to stop, I am also drunk.

Cut the crap, the following is written with CI's built-in image processing library

/ * generate thumbnails * @ param $path local path * @ return null create an original image _ thumb. File with extension * * / public function dealthumb ($path) {$config ['image_library'] =' gd2'; $config ['source_image'] = $path; $config [' create_thumb'] = TRUE; / / the resulting thumbnail will be close to the set width and height $config ['maintain_ratio'] = TRUE; $config [' width'] = 80; $config ['height'] = 80 in width and height $this- > load- > library ('image_lib', $config); $this- > image_lib- > resize (); $this- > image_lib- > clear ();} / * * handle image rotation * / public function transroate ($path,$imgpath) {$this- > load- > library (' image_lib'); / / (required) set image library $config ['image_library'] =' gd2'; $newname = time ().'_ rote.jpg' / / set the target name / path of the image $config ['new_image'] = $imgpath.$newname; / / (must) set the name / path of the original image $config [' source_image'] = $path; / / determine whether the generation of the new image is written to the hard disk or dynamically exist $config ['dynamic_output'] = FALSE; / / set the quality of the image. The higher the quality, the larger the image file $config ['quality'] =' 90% rotation; / / there are 5 rotation options counterclockwise 90 180 270 degrees vrt vertical flip hor horizontal flip $config ['rotation_angle'] =' vrt'; $this- > image_lib- > initialize ($config); if (@ $this- > image_lib- > rotate ()) {$this- > image_lib- > clear (); return $config ['new_image'] } else {$this- > image_lib- > clear (); return';}} / * * process image watermarking * / public function overlay ($path,$imgpath) {$this- > load- > library ('image_lib'); $newname = time ().' _ over.jpg'; / / set the new image name $config ['new_image'] = $imgpath.$newname / / call php gd library drawing $config ['image_library'] =' gd2'; / / source image local address $config ['source_image'] = $path; / / overlay text $config [' wm_text'] = 'Copyright 2015-Friker'; / / overlay type text / image $config [' wm_type'] = 'text' / / text font type / / $config ['wm_font_path'] =' C:\ Windows\ Fonts\ vrinda.ttf'; / / font size $config ['wm_font_size'] =' 16'; / / Font color $config ['wm_font_color'] =' ff0000'; / / Vertical distance from the top $config ['wm_vrt_alignment'] =' 20' / / horizontal distance to the left end $config ['wm_hor_alignment'] =' center'; / / padding $config ['wm_padding'] =' 20 years; $this- > image_lib- > initialize ($config); if ($this- > image_lib- > watermark ()) {$this- > image_lib- > clear (); return $config ['new_image'];} else {$this- > image_lib- > clear (); return'' }} / * handle picture upload * File upload class uploads files through the foreground * / public function uploadfile () {/ / File upload part / / process files / / $data =''; $this- > load- > helper ('url'); $formpic = key ($_ FILES) / / File processing part if (false = empty ($_ FILES [$formpic] ['tmp_name']) {/ / set the path of file upload $upload [' upload_path'] = ". / public/img/"; / / restrict the type of file upload $upload ['allowed_types'] =' jpeg | jpg | gif | png'; / / limit the size of file upload $upload ['max_size'] = 2048 / / set the path for file upload $upload ['file_name'] = date (' YmdHis', time ()) .rand (10000, 99999); / / load file upload configuration information $this- > load- > library ('upload', $upload); / / process file upload $this- > upload- > do_upload ($formpic); / / return file upload information $image = $this- > upload- > data () / * 'file_name' = > string' 2015071702051718388.jpg' (length=23) 'file_type' = > string' image/jpeg' (length=10) 'file_path' = > string'Elevue' (length=30) 'full_path' = > string' Vega 'full_path' = > string' Vega 'raw_name' = > string' 2015071702051718388' (length=19) 'orig_name' = > string' 2015071702051718388.jpg' (length=23) 'client_name' = > string'upright 415761610 1548338330fmlegs 116gpcards 0.jpg' (length=38) 'file_ext' = > string' .jpg'(length=4) 'file_size' = > float 3.74' is_image' = > boolean true 'image_width' = > int 146' image_height' = > int 220' Image_type' = > string 'jpeg' (length=4)' image_size_str' = > string 'width= "146" height= "220" (length=24) * / var_dump ($image) / / return file upload name $data = $image ['file_name']; $this- > dealthumb ($image [' full_path']); $this- > overlay ($image ['full_path'], $image [' file_path']); $this- > transroate ($image ['full_path'], $image [' file_path']); / / $thumbdata ='' / / generate thumbnail name $pos = strripos ($image ['file_name'], "."); $newname = substr ($image [' file_name'], 0Powerpos). "_ thumb" .substr ($image ['file_name'], $pos); if (file_exists ($image [' file_path']. $newname)) {$thumbdata = $newname;}} / / $dirroot = $SERVER ['DOCUMENT_ROOT'] / / $this- > dealthumb ($dirroot. "/ public/img/". $data); / / upload failed if (! $data) {echo json_encode ('status'= > 0 recording msg upload = > "upload failed!")) ;} else {/ / successfully uploaded echo json_encode (array ('name'= > $data,' pic'= > base_url (). "public/img/". $data, 'picthumb'= > $thumbdata = ='? $data:$thumbdata);}}

Here is the basic html code for the front end:

Body {background:#eeeeee; margin:0px;} share logo: (the optimal size is 80 X 80 pixels)

$(function () {/ * start of image upload section * / var act = "

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report