{"id":217544,"date":"2019-12-26T16:03:49","date_gmt":"2019-12-26T16:03:49","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=217544"},"modified":"2020-02-28T13:26:16","modified_gmt":"2020-02-28T13:26:16","slug":"php-methods-to-alter-images","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/","title":{"rendered":"PHP Methods To Alter Images"},"content":{"rendered":"\n<p>To set the images, we always need to find the images of the right dimensions to use it in our products. Sometimes it becomes very difficult to find the right images and it is also a very time taking process. Each place needs a different size and a different type of image. The choice of the right image also attracts the users, in e-commerce the right image plays an important role in user interaction.<\/p>\n\n\n\n<p>Here we have some methods in PHP to alter the images. It saves our time to search for the image of the right dimensions.<\/p>\n\n\n\n<p>Here are some steps to follow to resize an image with the PHP in-built method:<\/p>\n\n\n\n<p><strong>Step 1: <\/strong><\/p>\n\n\n\n<p><strong>imagecreatetruecolor($dest_width,$dest_height)<\/strong><\/p>\n\n\n\n<p>The method creates a blank image of the given height and width. That means the height and width in which we want to resize our image.<\/p>\n\n\n\n<p><strong>Step 2 :<\/strong><\/p>\n\n\n\n<p><strong>imagecopyresampled($dest_img,$src,0,0,0,0,$dest_width,$dest_height, $src_width,$src_height)<\/strong><\/p>\n\n\n\n<p>In the next step, we simply copy and resize our source image to our destination image, which means we resize the image from the original dimensions to the required dimensions.<\/p>\n\n\n\n<p><strong>$image_info = getimagesize($src_img)<\/strong><\/p>\n\n\n\n<p>Get the information of the image like, width, height, mime,size.<\/p>\n\n\n\n<p>$<strong>dest_img<\/strong> is the image in size we need. <strong>$src<\/strong> is the original image resource.<strong>$dest_width<\/strong> is our required width <strong>$dest_height<\/strong> is our required height. <strong>$src_width<\/strong> is the original image&#8217;s height and <strong>$src_height<\/strong> is the original image&#8217;s height.<\/p>\n\n\n\n<p><strong>Step 3 :<\/strong><\/p>\n\n\n\n<p><strong>imagejpeg($dest_img,$src_img);<\/strong><\/p>\n\n\n\n<p>It creates the image in our required image extension.<\/p>\n\n\n\n<p>Please check the given code snippet for the above explanation:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png\" alt=\"Selection_191\" class=\"wp-image-217566\" width=\"745\" height=\"334\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png 833w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191-300x135.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191-250x112.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191-768x345.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191-604x270.png 604w\" sizes=\"(max-width: 745px) 100vw, 745px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>This is the way we can alter the dimension of an image.<\/p>\n\n\n\n<p>In case you have any queries then feel free to ask in the comment section below.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To set the images, we always need to find the images of the right dimensions to use it in our products. Sometimes it becomes very difficult to find the right images and it is also a very time taking process. Each place needs a different size and a different type of image. The choice of <a href=\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":221,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-217544","post","type-post","status-publish","format-standard","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP Methods To Alter Images - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Methods To Alter Images - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"To set the images, we always need to find the images of the right dimensions to use it in our products. Sometimes it becomes very difficult to find the right images and it is also a very time taking process. Each place needs a different size and a different type of image. The choice of [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-26T16:03:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-02-28T13:26:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png\" \/>\n<meta name=\"author\" content=\"Sweta Som\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sweta Som\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/\"},\"author\":{\"name\":\"Sweta Som\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/fdc8428281225cfb70eb43d6cd066362\"},\"headline\":\"PHP Methods To Alter Images\",\"datePublished\":\"2019-12-26T16:03:49+00:00\",\"dateModified\":\"2020-02-28T13:26:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/\"},\"wordCount\":304,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png\",\"articleSection\":[\"php\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/\",\"url\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/\",\"name\":\"PHP Methods To Alter Images - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png\",\"datePublished\":\"2019-12-26T16:03:49+00:00\",\"dateModified\":\"2020-02-28T13:26:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png\",\"width\":833,\"height\":374,\"caption\":\"Selection_191\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP Methods To Alter Images\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/fdc8428281225cfb70eb43d6cd066362\",\"name\":\"Sweta Som\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cea77654a5ab26ecf23e54c00ae634403aa031ca70a870e4bfc716e114f2087e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cea77654a5ab26ecf23e54c00ae634403aa031ca70a870e4bfc716e114f2087e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Sweta Som\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/swetasom-oc891\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Methods To Alter Images - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/","og_locale":"en_US","og_type":"article","og_title":"PHP Methods To Alter Images - Webkul Blog","og_description":"To set the images, we always need to find the images of the right dimensions to use it in our products. Sometimes it becomes very difficult to find the right images and it is also a very time taking process. Each place needs a different size and a different type of image. The choice of [...]","og_url":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2019-12-26T16:03:49+00:00","article_modified_time":"2020-02-28T13:26:16+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png","type":"","width":"","height":""}],"author":"Sweta Som","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Sweta Som","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/"},"author":{"name":"Sweta Som","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/fdc8428281225cfb70eb43d6cd066362"},"headline":"PHP Methods To Alter Images","datePublished":"2019-12-26T16:03:49+00:00","dateModified":"2020-02-28T13:26:16+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/"},"wordCount":304,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png","articleSection":["php"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/","url":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/","name":"PHP Methods To Alter Images - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png","datePublished":"2019-12-26T16:03:49+00:00","dateModified":"2020-02-28T13:26:16+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2019\/12\/Selection_191.png","width":833,"height":374,"caption":"Selection_191"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/php-methods-to-alter-images\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP Methods To Alter Images"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/fdc8428281225cfb70eb43d6cd066362","name":"Sweta Som","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cea77654a5ab26ecf23e54c00ae634403aa031ca70a870e4bfc716e114f2087e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cea77654a5ab26ecf23e54c00ae634403aa031ca70a870e4bfc716e114f2087e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Sweta Som"},"url":"https:\/\/webkul.com\/blog\/author\/swetasom-oc891\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/217544","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/221"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=217544"}],"version-history":[{"count":12,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/217544\/revisions"}],"predecessor-version":[{"id":218030,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/217544\/revisions\/218030"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=217544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=217544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=217544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}