In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to convert php image types". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to convert php image types.
Php image type to achieve conversion methods: 1, create a PHP sample file; 2, through the "function image_change ($image_path, $to_ext = 'png',$save_path=null) {.}" method to achieve conversion.
This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.
How to convert php image types?
The method of php Picture format conversion
/ * Image format conversion * @ param string $image_path file path or url * @ param string $to_ext format to be converted. Support png,gif,jpeg,wbmp,webp,xbm * @ param null | string $save_path storage path, null returns binary content, string returns true | false * @ return boolean | string $save_path returns binary content if null String returns true | false * @ throws Exception * / function image_change ($image_path, $to_ext = 'png', $save_path = null) {if (! in_array ($to_ext, [' png', 'gif',' jpeg', 'wbmp',' webp', 'xbm'])) {throw new\ Exception (' unsupport transform image to'. $to_ext);} switch (exif_imagetype ($image_path)) {case IMAGETYPE_GIF: $img = imagecreatefromgif ($image_path); break; case IMAGETYPE_JPEG: case IMAGETYPE_JPEG2000: $img = imagecreatefromjpeg ($image_path); break; case IMAGETYPE_PNG: $img = imagecreatefrompng ($image_path); break Case IMAGETYPE_BMP: case IMAGETYPE_WBMP: $img = imagecreatefromwbmp ($image_path); break; case IMAGETYPE_XBM: $img = imagecreatefromxbm ($image_path); break; case IMAGETYPE_WEBP: / / (supported since PHP 7.1.0) $img = imagecreatefromwebp ($image_path); break Default: throw new\ Exception ('Invalid image type');} $function =' image'. $to_ext; if ($save_path) {return $function ($img, $save_path);} else {$tmp = _ _ DIR__. '/'. Uniqid (). '.'. $to_ext; if ($function ($img, $tmp)) {$content = file_get_contents ($tmp); unlink ($tmp); return $content;} else {unlink ($tmp); throw new\ Exception ('the file'. $tmp. ' Can not write');} at this point, I believe you have a deeper understanding of "how to convert php image types". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.