{"id":16396,"date":"2020-07-17T12:27:05","date_gmt":"2020-07-17T12:27:05","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=16396"},"modified":"2021-10-30T06:12:40","modified_gmt":"2021-10-30T06:12:40","slug":"image-convert-to-jpg-png-gif-using-php","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/image-convert-to-jpg-png-gif-using-php\/","title":{"rendered":"Image Convert  to JPG, PNG &#038; GIF using PHP"},"content":{"rendered":"\n<p>In this post I help you to convert any uploaded image to JPG, PNG and GIF.<\/p>\n\n\n\n<p>Create a file <strong>image_converter.php.<\/strong><\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/narayanlog\/1d6b931eda612fe672349250558859ce.js\"><\/script>\n\n\n\n<p>In this code you see using convert_image() has three mandatory parameters like as:<\/p>\n\n\n\n<p><strong>$convert_type<\/strong> =&gt; accepts string either png,jpg or gif.<br><strong>$target_dir<\/strong> =&gt; it is the source as well as the target directory<br><strong>$image_name<\/strong> =&gt; give the actual image name such as image1.jpg.<br><strong>$image_quality<\/strong> =&gt; can be adjusted, if you don&#8217;t want 100% quality.<\/p>\n\n\n\n<p>Next, create <strong>index.php<\/strong> to Upload the image.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/narayanlog\/3adb1284db72fdac67ff78423725b220.js\"><\/script>\n\n\n\n<p>Then, create <strong>convert.php<\/strong> to convert the image. And make a folder in your directory name as <strong>uploads<\/strong>. Because when the image is uploaded or convert, the image will save on this folder.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/narayanlog\/07543213eeae60090a8833fc8ea5cf25.js\"><\/script>\n\n\n\n<p>And, create a <strong>download.php<\/strong> to downloads the converted image forcefully.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/narayanlog\/99809e6051b86024fb8205c767aa1833.js\"><\/script>\n\n\n\n<p>Then, Run the <strong>index.php<\/strong> and see the view.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/index.png\" alt=\"\" class=\"wp-image-16397\" width=\"472\" height=\"183\"\/><\/figure>\n\n\n\n<p>After <strong>Upload<\/strong> the image.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/after-upload.png\" alt=\"\" class=\"wp-image-16398\" width=\"268\" height=\"294\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/after-upload.png 486w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/after-upload-274x300.png 274w\" sizes=\"auto, (max-width: 268px) 100vw, 268px\" \/><\/figure>\n\n\n\n<p>After <strong>converted<\/strong> the image.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/converted.png\" alt=\"\" class=\"wp-image-16399\" width=\"275\" height=\"317\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/converted.png 433w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/07\/converted-260x300.png 260w\" sizes=\"auto, (max-width: 275px) 100vw, 275px\" \/><\/figure>\n\n\n\n<p>Then, you can download or convert another image.<\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_77451\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_56724\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_77451\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>In this post I help you to convert any uploaded image to JPG, PNG and GIF. Create a file image_converter.php. In this code you see using convert_image() has three mandatory parameters like as: $convert_type =&gt; accepts string either png,jpg or gif.$target_dir =&gt; it is the source as well as the target directory$image_name =&gt; give the&#8230;<\/p>\n","protected":false},"author":9,"featured_media":16400,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[5150],"tags":[177],"class_list":["post-16396","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/16396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=16396"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/16396\/revisions"}],"predecessor-version":[{"id":24659,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/16396\/revisions\/24659"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/16400"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=16396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=16396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=16396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}