{"id":1150,"date":"2012-10-24T23:53:08","date_gmt":"2012-10-24T23:53:08","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=1150"},"modified":"2012-10-24T23:53:08","modified_gmt":"2012-10-24T23:53:08","slug":"php-how-to-dynamically-resize-image-in-your-page","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2012\/10\/php-how-to-dynamically-resize-image-in-your-page\/","title":{"rendered":"PHP: How to dynamically resize image in your page?"},"content":{"rendered":"<p>Every php programmer\/developer have to resize images in web pages.<br \/>\nThere are a lot of ways available through JavaScript, jQuery and PHP.<br \/>\nHere is very simple way to resize image temporarily but proportionally.<br \/>\nYou can still keep big image file in you in your folder but when you are displaying you can make is smaller. <\/p>\n<p>Jquery and java script some times does not work.  So PHP way is very useful. <\/p>\n<pre lang=\"php\">\r\n\r\n<?php \r\n$your_image = 'mybig_image.jpg';\r\n$inputwidth = 200;\r\n$inputheight = 200;\r\n\r\nlist($width,$height) = getimagesize($your_image);\r\n\r\nif (($width\/$height) > ($inputwidth\/$inputheight)) {\r\n            $outputwidth = $inputwidth;\r\n            $outputheight = ($inputwidth * $height)\/ $width;\r\n        }\r\n\r\n        elseif (($width\/$height) < ($inputwidth\/$inputheight)) {\r\n            $outputwidth = ($inputheight * $width)\/ $height;\r\n            $outputheight = $inputheight;\r\n        }\r\n\r\n        elseif (($width\/$height) == ($inputwidth\/$inputheight)) {\r\n            $outputwidth = $inputwidth;\r\n            $outputheight = $inputheight;\r\n            }\r\n\r\necho '<img decoding=\"async\" src=\"'.$your_image.'\" width=\"'.$outputwidth.'\" height=\"'.$outputheight.'\">';\r\n\r\n?>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Every php programmer\/developer have to resize images in web pages. There are a lot of ways available through JavaScript, jQuery and PHP. Here is very simple way to resize image temporarily but proportionally. You can still keep big image file in you in your folder but when you are displaying you can make is smaller. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1150","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=1150"}],"version-history":[{"count":1,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1150\/revisions"}],"predecessor-version":[{"id":1151,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1150\/revisions\/1151"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=1150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=1150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=1150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}