How to realize the picture class of saving pictures as pictures of different sizes by php
This article is about how php can save pictures as pictures of different sizes. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The details are as follows:
The image processing class .imagecls.php is as follows:
2.get_spec_img () calls the picture class, and then saves the pictures of different specifications and returns the picture connection with the following method
/ / get the image address of the appropriate specification / / gen=0: keep the scale and do not cut. If the height is 0, make sure the width is scaled gen=1: ensure the length and width, clip function get_spec_image ($img_path,$width=0,$height=0,$gen=0,$is_preview=true) {if ($width==0) $new_path = $img_path; else {$img_name = substr ($img_path,0,-4); $img_ext = substr ($img_path,-3) If ($is_preview) $new_path = $img_name. "_". $width. "x". $height. ".jpg"; else $new_path = $img_name. "o _". $width. "x". $height. ".jpg"; if (! file_exists ($new_path)) {require_once "imagecls.php"; $imagec = new imagecls () $thumb = $imagec- > thumb ($img_path,$width,$height,$gen,true, ", $is_preview); if (app_conf (" PUBLIC_DOMAIN_ROOT ")! =') {$paths = pathinfo ($new_path); $path = str_replace (". / ",", $paths ['dirname']); $filename = $paths [' basename']; $pathwithoupublic = str_replace ("public/", "", $path) $file_data = @ file_get_contents ($path.$file); $img = @ imagecreatefromstring ($file_data); if ($imgrams created false) {$save_path = "public/". $path; if (! is_dir ($save_path)) {@ mk_dir ($save_path) } @ file_put_contents ($save_path.$name,$file_data);}} return $new_path;}
3. How to use it:
/ / im: save the store picture in 3 specifications: small image: 48x48, middle picture 120x120, large picture 200x200 $small_url=get_spec_image ($data ['image'], 48,48lemen0); $middle_url=get_spec_image ($data [' image'], 120memrici0); $big_url=get_spec_image ($data ['image'], 200cen200); Thank you for reading! About "php how to save pictures as pictures of different sizes" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!