{"id":673,"date":"2025-06-11T12:35:31","date_gmt":"2025-06-11T04:35:31","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/xtywj\/673.html"},"modified":"2025-06-11T12:35:31","modified_gmt":"2025-06-11T04:35:31","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8php%e4%b8%ad%e6%9b%b4%e6%94%b9%e5%9b%be%e5%83%8f%e7%b1%bb%e5%9e%8b%ef%bc%88jpg-png-gif%ef%bc%89%e8%80%8c%e4%b8%8d%e5%a4%b1%e7%9c%9f","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/673.html","title":{"rendered":"\u5982\u4f55\u5728PHP\u4e2d\u66f4\u6539\u56fe\u50cf\u7c7b\u578b\uff08JPG\/PNG\/GIF\uff09\u800c\u4e0d\u5931\u771f"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">Bug&#32534;&#35793;&#29422;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; PHP &#20013;&#26356;&#25913;&#22270;&#20687;&#31867;&#22411;&#65288;&#22914; JPG&#12289;PNG &#21644; GIF&#65289;&#32780;&#19981;&#22833;&#30495;&#65292;&#36890;&#24120;&#38656;&#35201;&#20351;&#29992;&#19968;&#20123;&#24211;&#26469;&#22788;&#29702;&#22270;&#29255;&#65292;&#24182;&#30830;&#20445;&#22270;&#20687;&#30340;&#20687;&#32032;&#36136;&#37327;&#21644;&#33394;&#24425;&#20934;&#30830;&#24615;&#19981;&#21463;&#24433;&#21709;&#12290;&#20197;&#19979;&#26159;&#19968;&#20010;&#31034;&#20363;&#20195;&#30721;&#65292;&#23637;&#31034;&#20102;&#22914;&#20309;&#20351;&#29992; GD &#24211;&#26469;&#23454;&#29616;&#36825;&#19968;&#30446;&#26631;&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\/\/ &#21407;&#22987;&#22270;&#20687;&#36335;&#24452;\n$originalImagePath = 'path\/to\/original\/image.jpg';\n\n\/\/ &#30446;&#26631;&#22270;&#20687;&#36335;&#24452;\n$targetImagePath = 'path\/to\/target\/image.png';\n\n\/\/ &#25171;&#24320;&#21407;&#22987;&#22270;&#20687;\n$image = imagecreatefromjpeg($originalImagePath);\n\nif ($image === false) {\n    die('&#26080;&#27861;&#25171;&#24320;&#21407;&#22987;&#22270;&#20687;');\n}\n\n\/\/ &#35774;&#32622;&#30446;&#26631;&#22270;&#20687;&#30340;&#22823;&#23567;\nlist($width, $height) = getimagesize($originalImagePath);\n$newWidth = 800;\n$newHeight = 600;\n\n\/\/ &#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#22270;&#20687;&#36164;&#28304;\n$newImage = imagecreatetruecolor($newWidth, $newHeight);\n\n\/\/ &#23558;&#21407;&#22270;&#20687;&#22797;&#21046;&#21040;&#26032;&#22270;&#20687;&#20013;\nimagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);\n\n\/\/ &#20445;&#23384;&#26032;&#30340;&#22270;&#20687;\nimagepng($newImage, $targetImagePath);\n\n\/\/ &#20851;&#38381;&#22270;&#20687;&#36164;&#28304;\nimagedestroy($image);\nimagedestroy($newImage);\n\necho \"&#22270;&#20687;&#24050;&#25104;&#21151;&#36716;&#25442;&#20026; PNG &#26684;&#24335;&#24182;&#20445;&#23384;&#21040; $targetImagePath\";\n?&gt;<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#31034;&#20363;&#20013;&#65292;&#25105;&#20204;&#39318;&#20808;&#20351;&#29992; <code>imagecreatefromjpeg<\/code> &#20989;&#25968;&#25171;&#24320;&#21407;&#22987;&#22270;&#20687;&#25991;&#20214;&#12290;&#28982;&#21518;&#65292;&#25105;&#20204;&#35774;&#32622;&#30446;&#26631;&#22270;&#20687;&#30340;&#22823;&#23567;&#65292;&#24182;&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#22270;&#20687;&#36164;&#28304; <code>imagecreatetruecolor<\/code>&#12290;&#25509;&#30528;&#65292;&#25105;&#20204;&#20351;&#29992; <code>imagecopyresampled<\/code> &#20989;&#25968;&#23558;&#21407;&#22270;&#20687;&#22797;&#21046;&#21040;&#26032;&#22270;&#20687;&#20013;&#65292;&#20197;&#20445;&#25345;&#22270;&#20687;&#30340;&#36136;&#37327;&#21644;&#33394;&#24425;&#12290;&#26368;&#21518;&#65292;&#25105;&#20204;&#23558;&#26032;&#22270;&#20687;&#20445;&#23384;&#20026; PNG &#26684;&#24335;&#12290;<\/p>\n<p>&#35831;&#27880;&#24847;&#65292;&#36825;&#20010;&#31034;&#20363;&#20551;&#35774;&#20320;&#24050;&#32463;&#23433;&#35013;&#20102; GD &#24211;&#65292;&#24182;&#19988;&#20320;&#30340;&#26381;&#21153;&#22120;&#19978;&#25903;&#25345; PHP &#30340; GD &#27169;&#22359;&#12290;&#22914;&#26524;&#20320;&#20351;&#29992;&#30340;&#26159;&#20854;&#20182;&#22270;&#20687;&#22788;&#29702;&#24211;&#65288;&#22914; ImageMagick&#65289;&#65292;&#27493;&#39588;&#21487;&#33021;&#20250;&#26377;&#25152;&#19981;&#21516;&#65292;&#20294;&#22522;&#26412;&#24605;&#36335;&#26159;&#30456;&#20284;&#30340;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;Bug&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#40657;&#26495;Bug&#35762;&#24072;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><h2>&#20171;&#32461;<\/h2><p>&#22270;&#29255;&#36890;&#24120;&#22312;&#32593;&#31449;&#30340;&#25968;&#25454;&#20013;&#21344;&#25454;&#26368;&#22823;&#30340;&#37096;&#20998;&#65292;&#19981;&#21516;&#30340;&#26684;&#24335;&#21487;&#20197;&#28385;&#36275;&#21508;&#31181;&#38656;&#27714;&#12290;&#22914;&#26524;&#20320;&#24076;&#26395;&#21152;&#24555;&#32593;&#31449;&#36895;&#24230;&#12289;&#33410;&#30465;&#23384;&#20648;&#31354;&#38388;&#25110;&#32773;&#20351;&#22270;&#20687;&#33021;&#22815;&#22312;&#19981;&#21516;&#27983;&#35272;&#22120;&#21644;&#35774;&#22791;&#19978;&#20860;&#23481;&#65292;&#20102;&#35299;&#22914;&#20309;&#39640;&#25928;&#22320;&#36716;&#25442;&#22270;&#20687;&#32780;&#19981;&#29306;&#29298;&#36136;&#37327;&#33267;&#20851;&#37325;&#35201;&#12290;&#26412;&#25945;&#31243;&#23558;&#25945;&#20320;&#22914;&#20309;&#20351;&#29992;PHP&#22312;&#19981;&#25439;&#23475;&#22270;&#20687;&#23436;&#25972;&#24615;&#30340;&#24773;&#20917;&#19979;&#26356;&#25913;&#22270;&#20687;&#31867;&#22411;&#12290;<\/p><h3>&#29702;&#35299;&#22270;&#20687;&#26684;&#24335;<\/h3><p>&#22312;&#28145;&#20837;&#25216;&#26415;&#32454;&#33410;&#20043;&#21069;&#65292;&#35753;&#25105;&#20204;&#31616;&#35201;&#22238;&#39038;&#19968;&#19979;&#27969;&#34892;&#30340;&#22270;&#20687;&#26684;&#24335;&#65306;JPG&#12289;PNG&#21644;GIF&#12290;JPG&#22270;&#20687;&#38750;&#24120;&#21387;&#32553;&#65292;&#25903;&#25345;&#25968;&#30334;&#19975;&#31181;&#39068;&#33394;&#65292;&#38750;&#24120;&#36866;&#21512;&#29031;&#29255;&#12290;PNG&#26159;&#26080;&#25439;&#30340;&#65292;&#25903;&#25345;&#36879;&#26126;&#24230;&#65292;&#36866;&#21512;&#20855;&#26377;&#28165;&#26224;&#36793;&#32536;&#30340;&#22270;&#24418;&#22270;&#20687;&#12290;GIF&#20063;&#26159;&#26080;&#25439;&#30340;&#65292;&#25903;&#25345;&#31616;&#21333;&#21160;&#30011;&#65292;&#26368;&#22810;&#21482;&#33021;&#20351;&#29992;256&#31181;&#39068;&#33394;&#12290;<\/p><h3>&#20808;&#20915;&#26465;&#20214;<\/h3><p>PHP&#30340;&#22522;&#26412;&#30693;&#35782;&#12290;<\/p><p>&#22312;PHP&#20013;&#24050;&#21551;&#29992;GD&#24211;&#12290;<\/p><p>PHP&#24050;&#23433;&#35013;&#22312;&#24744;&#30340;&#26381;&#21153;&#22120;&#19978;&#12290;<\/p><h2>&#24320;&#22987;&#20351;&#29992;GD&#24211;<\/h2><p>GD &#22270;&#24418;&#32472;&#21046;&#24211;&#26159;&#19968;&#20010;&#25552;&#20379;&#22270;&#20687;&#25968;&#25454;&#25805;&#20316;&#24037;&#20855;&#30340;&#22270;&#24418;&#24211;&#12290;&#22312;&#20351;&#29992; GD &#24211;&#20989;&#25968;&#20043;&#21069;&#65292;&#35831;&#30830;&#20445;&#23427;&#20204;&#24050;&#21551;&#29992;&#65292;&#21487;&#20197;&#36890;&#36807;&#26816;&#26597;&#24744;&#30340; php.ini &#25991;&#20214;&#25110;&#20351;&#29992; phpinfo() &#20989;&#25968;&#26469;&#23454;&#29616;&#12290;<\/p><pre><code>if (extension_loaded('gd') &amp;&amp; function_exists('gd_info')) {\n    echo 'GD library is enabled on your server.';\n} else {\n    echo 'You need to enable GD library.';\n}<\/code><\/pre><h2>&#27491;&#22312;&#21152;&#36733;&#22270;&#20687;&#12290;<\/h2><p>&#39318;&#20808;&#65292;&#20351;&#29992;&#22270;&#20687;&#21019;&#24314;&#21151;&#33021;&#20043;&#19968;&#21152;&#36733;&#22270;&#20687;&#65292;&#20855;&#20307;&#21462;&#20915;&#20110;&#22270;&#20687;&#30340;&#24403;&#21069;&#26684;&#24335;&#65306;<\/p><p>&#20351;&#29992; imagecreatefromgif() &#20989;&#25968;&#21487;&#20197;&#35835;&#21462;&#21644;&#21019;&#24314;&#20174; GIF &#26684;&#24335;&#25991;&#20214;&#21152;&#36733;&#30340;&#22270;&#20687;&#12290;<\/p><p>&#20351;&#29992; imagecreatefrompng() &#20989;&#25968;&#20174; PNG &#25991;&#20214;&#21019;&#24314;&#22270;&#20687;&#12290;<\/p><p>&#20351;&#29992; imagecreatefromjpeg() &#20989;&#25968;&#20174; JPEG &#25991;&#20214;&#21019;&#24314;&#22270;&#20687;&#12290;<\/p><p>&#20197;&#19979;&#26159;&#22914;&#20309;&#21152;&#36733;JPEG&#22270;&#20687;&#30340;&#26041;&#27861;&#65306;<\/p><pre><code>$imgPath = 'path\/to\/your\/image.jpg';\n$image = imagecreatefromjpeg($imgPath);<\/code><\/pre><h2>&#36716;&#25442;&#22270;&#29255;<\/h2><p>&#35201;&#36716;&#25442;&#20026;&#19981;&#21516;&#26684;&#24335;&#65292;&#35831;&#20351;&#29992;&#30456;&#24212;&#36755;&#20986;&#20989;&#25968;&#20043;&#19968;&#65306;<\/p><p>&#25265;&#27465;&#65292;&#25105;&#26080;&#27861;&#29702;&#35299;&#24744;&#25552;&#20379;&#30340;&#20449;&#24687;&#12290;&#35831;&#29992;&#20013;&#25991;&#25552;&#38382;&#25110;&#25551;&#36848;&#65292;&#25105;&#20250;&#23613;&#21147;&#24110;&#21161;&#24744;&#12290;<\/p><p>&#35831;&#25552;&#20379;&#26356;&#22810;&#20449;&#24687;&#65292;&#20197;&#20415;&#25105;&#33021;&#22815;&#20026;&#24744;&#25552;&#20379;&#20934;&#30830;&#30340;&#24110;&#21161;&#21644;&#32763;&#35793;&#12290;<\/p><p>JPEG&#65288;Joint Photographic Experts Group&#65289;&#30340;&#22270;&#20687;&#21387;&#32553;&#31639;&#27861;&#65292;&#29992;&#20110;JPG&#26684;&#24335;&#12290;<\/p><p>&#22914;&#26524;&#20320;&#26377;&#19968;&#20010;PNG&#22270;&#20687;&#24182;&#24819;&#22312;&#19981;&#20002;&#22833;&#36136;&#37327;&#30340;&#24773;&#20917;&#19979;&#23558;&#20854;&#36716;&#25442;&#20026;JPG&#26684;&#24335;&#65292;&#21487;&#20197;&#25351;&#23450;&#36755;&#20986;&#36136;&#37327;&#65288;&#26368;&#22823;&#20540;&#20026;100&#65289;&#20316;&#20026;&#31532;&#20108;&#20010;&#21442;&#25968;&#65306;<\/p><pre><code>header('Content-Type: image\/jpeg');\nimagejpeg($image, null, 100);<\/code><\/pre><h2>&#20445;&#23384;&#36716;&#25442;&#21518;&#30340;&#22270;&#20687;<\/h2><p>&#20026;&#20102;&#20445;&#23384;&#26032;&#36716;&#25442;&#30340;&#22270;&#20687;&#65292;&#35831;&#22312;&#36755;&#20986;&#20989;&#25968;&#20013;&#36890;&#36807;&#31532;&#20108;&#20010;&#21442;&#25968;&#20256;&#36882;&#25991;&#20214;&#21517;&#65306;<\/p><pre><code>imagejpeg($image, 'path\/to\/save\/newimage.jpg', 100);<\/code><\/pre><h2>&#22312;PNG&#25991;&#20214;&#20013;&#20445;&#30041;Alpha&#36890;&#36947;<\/h2><p>&#22312;&#36716;&#25442;&#20026;PNG&#26684;&#24335;&#26102;&#65292;&#21153;&#24517;&#20445;&#30041;&#36879;&#26126;&#36890;&#36947;&#20197;&#20445;&#25345;&#36879;&#26126;&#24230;&#12290;&#20351;&#29992;imagesavealpha()&#21644;imagealphablending()&#20989;&#25968;&#65306;<\/p><pre><code>imagealphablending($image, false);\nimagesavealpha($image, true);\nimagepng($image, 'path\/to\/save\/newimage.png');<\/code><\/pre><h2>&#35843;&#25972;&#22270;&#29255;&#22823;&#23567;<\/h2><p>&#26377;&#26102;&#25913;&#21464;&#26684;&#24335;&#21487;&#33021;&#24847;&#21619;&#30528;&#37325;&#26032;&#32553;&#25918;&#22270;&#20687;&#12290;&#21487;&#20197;&#20351;&#29992;imagesx()&#21644;imagesy()&#33719;&#21462;&#24403;&#21069;&#23610;&#23544;&#65292;&#28982;&#21518;&#20351;&#29992;imagecopyresampled()&#36827;&#34892;&#37325;&#32622;&#65306;<\/p><pre><code>$width = imagesx($image);\n$height = imagesy($image);\n$newWidth = $width \/ 2;\n$newHeight = $height \/ 2;\n\n$resizedImage = imagecreatetruecolor($newWidth, $newHeight);\nimagecopyresampled($resizedImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);<\/code><\/pre><h2>&#26368;&#20339;&#23454;&#36341;<\/h2><p>&#20351;&#29992;&#36866;&#24403;&#30340;&#21387;&#32553;&#32423;&#21035;&#26469;&#24179;&#34913;&#36136;&#37327;&#19982;&#25991;&#20214;&#22823;&#23567;&#12290;<\/p><p>&#22312;&#36716;&#25442;&#20026;&#26684;&#24335;&#20043;&#21069;&#65292;&#32771;&#34385;&#22270;&#20687;&#30340;&#24615;&#36136;&#21644;&#29305;&#24615;&#20197;&#36991;&#20813;&#19981;&#24517;&#35201;&#30340;&#36136;&#37327;&#25439;&#22833;&#25110;&#25991;&#20214;&#22823;&#23567;&#22686;&#21152;&#12290;<\/p><p>&#22312;&#39564;&#35777;&#32467;&#26524;&#28385;&#24847;&#20043;&#21069;&#65292;&#19981;&#35201;&#35206;&#30422;&#21407;&#22987;&#22270;&#20687;&#12290;<\/p><h2>&#26368;&#21518;&#30340;&#24819;&#27861;<\/h2><p>&#26412;&#25945;&#31243;&#25506;&#35752;&#20102;&#20351;&#29992;PHP&#26356;&#25913;&#22270;&#20687;&#31867;&#22411;&#30340;&#36807;&#31243;&#65292;&#29305;&#21035;&#24378;&#35843;&#20102;GD&#24211;&#30340;&#20316;&#29992;&#12290;&#27491;&#30830;&#21033;&#29992;&#36825;&#20123;&#24037;&#20855;&#24182;&#29702;&#35299;&#27599;&#31181;&#22270;&#20687;&#26684;&#24335;&#30340;&#24494;&#22937;&#20043;&#22788;&#65292;&#21487;&#20197;&#39640;&#25928;&#22320;&#23558;JPG&#36716;&#25442;&#20026;PNG&#25110;GIF&#65292;&#21453;&#20043;&#20134;&#28982;&#65292;&#32780;&#19981;&#29306;&#29298;&#36136;&#37327;&#12290;<\/p><p>&#35831;&#35760;&#20303;&#65292;&#34429;&#28982;&#36825;&#20221;&#25351;&#21335;&#20026;&#36215;&#28857;&#65292;&#20294;&#20851;&#20110;&#22270;&#20687;&#22788;&#29702;&#21644;&#32534;&#36753;&#30340;&#32454;&#33410;&#36824;&#26377;&#24456;&#22810;&#38656;&#35201;&#23398;&#20064;&#12290;&#36890;&#36807;&#32451;&#20064;&#21644;&#25506;&#32034;&#65292;&#20320;&#21487;&#20197;&#20248;&#21270;&#32593;&#31449;&#23186;&#20307;&#20197;&#25552;&#39640;&#24615;&#33021;&#21644;&#29992;&#25143;&#20307;&#39564;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--3\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/xygcfznnzczhsdmwydzhsmzzzmddnq-400x300.jpg\" alt=\"&#38271;&#24037;&#30721;&#22900;1523\" class=\"wp-image-2906\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#38271;&#24037;&#30721;&#22900;1523<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312;PHP&#20013;&#26356;&#25913;&#22270;&#20687;&#31867;&#22411;&#24182;&#20445;&#25345;&#19981;&#22833;&#30495;&#30340;&#26041;&#27861;&#26377;&#24456;&#22810;&#65292;&#20294;&#26368;&#24120;&#29992;&#19988;&#30456;&#23545;&#31616;&#21333;&#30340;&#26041;&#27861;&#26159;&#20351;&#29992;Gd&#24211;&#12290;Gd&#26159;&#19968;&#31181;&#24320;&#28304;&#30340;&#12289;&#21151;&#33021;&#24378;&#22823;&#30340;&#22270;&#20687;&#22788;&#29702;&#24211;&#65292;&#23427;&#25903;&#25345;&#22810;&#31181;&#22270;&#20687;&#26684;&#24335;&#65292;&#21253;&#25324;JPEG&#12289;PNG&#21644;GIF&#31561;&#12290;<\/p>\n<p>&#20197;&#19979;&#26159;&#22914;&#20309;&#20351;&#29992;Gd&#24211;&#23558;&#22270;&#20687;&#20174;&#19968;&#31181;&#26684;&#24335;&#36716;&#25442;&#20026;&#21478;&#19968;&#31181;&#26684;&#24335;&#30340;&#31034;&#20363;&#65306;<\/p>\n<ol>\n<li>\n<p>&#39318;&#20808;&#65292;&#30830;&#20445;&#24050;&#23433;&#35013;GD&#24211;&#12290;&#22914;&#26524;&#27809;&#26377;&#65292;&#21487;&#20197;&#36890;&#36807;Composer&#36827;&#34892;&#23433;&#35013;&#65306;<\/p>\n<pre><code class=\"language-bash\">composer require gd2\/php-gd<\/code><\/pre>\n<\/li>\n<li>\n<p>&#28982;&#21518;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;&#20197;&#19979;PHP&#20989;&#25968;&#26469;&#26356;&#25913;&#22270;&#20687;&#31867;&#22411;&#65306;<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"language-php\">function convertImage($sourcePath, $targetFormat) {\n    \/\/ &#23558;&#25991;&#20214;&#35835;&#20837;&#20869;&#23384;\n    $image = imagecreatefromjpeg($sourcePath);\n\n    \/\/ &#26816;&#26597;&#26159;&#21542;&#25104;&#21151;&#21152;&#36733;&#20102;&#22270;&#20687;\n    if ($image === false) {\n        throw new Exception('Could not load image.');\n    }\n\n    \/\/ &#26681;&#25454;&#30446;&#26631;&#26684;&#24335;&#21019;&#24314;&#26032;&#22270;&#20687;\n    switch ($targetFormat) {\n        case 'jpg':\n            $newImage = imagecreatetruecolor(400, 300);\n            break;\n        case 'png':\n            $newImage = imagecreatetruecolor(400, 300);\n            break;\n        case 'gif':\n            $newImage = imagecreate(400, 300);\n            break;\n        default:\n            throw new Exception('Unsupported format');\n    }\n\n    \/\/ &#23558;&#21407;&#22270;&#22797;&#21046;&#21040;&#26032;&#22270;&#19978;\n    imagecopyresampled($newImage, $image, 0, 0, 0, 0, 400, 300, 400, 300);\n\n    \/\/ &#20445;&#23384;&#26032;&#30340;&#22270;&#20687;&#21040;&#25351;&#23450;&#20301;&#32622;\n    $targetFile = \"path\/to\/new\/$targetFormat\";\n    imagedestroy($image);\n    imagejpeg($newImage, $targetFile);\n\n    return true;\n}<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;&#25105;&#20204;&#39318;&#20808;&#36890;&#36807;<code>imagecreatefromjpeg()<\/code>&#20989;&#25968;&#21152;&#36733;&#28304;&#22270;&#20687;&#65292;&#24182;&#26816;&#26597;&#20854;&#25104;&#21151;&#19982;&#21542;&#12290;&#28982;&#21518;&#65292;&#26681;&#25454;&#30446;&#26631;&#26684;&#24335;&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#22270;&#20687;&#12290;&#26368;&#21518;&#65292;&#25105;&#20204;&#23558;&#28304;&#22270;&#20687;&#22797;&#21046;&#21040;&#26032;&#22270;&#20687;&#19978;&#65292;&#24182;&#20351;&#29992;<code>imagedestroy()<\/code>&#37322;&#25918;&#36164;&#28304;&#12290;<\/p>\n<p>&#35831;&#27880;&#24847;&#65292;&#36825;&#21482;&#26159;&#19968;&#20010;&#22522;&#26412;&#30340;&#20363;&#23376;&#65292;&#23454;&#38469;&#25805;&#20316;&#21487;&#33021;&#20250;&#26377;&#25152;&#19981;&#21516;&#65292;&#20363;&#22914;&#38656;&#35201;&#22788;&#29702;&#38169;&#35823;&#24773;&#20917;&#12289;&#35843;&#25972;&#22270;&#20687;&#22823;&#23567;&#31561;&#12290;&#27492;&#22806;&#65292;&#24744;&#36824;&#21487;&#20197;&#23581;&#35797;&#20351;&#29992;&#20854;&#20182;&#22270;&#20687;&#22788;&#29702;&#24211;&#22914;Imagick&#65292;&#23427;&#20204;&#25552;&#20379;&#20102;&#26356;&#20016;&#23500;&#30340;&#21151;&#33021;&#21644;&#36873;&#39033;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312; PHP &#20013;&#26356;&#25913;&#22270;&#20687;&#31867;&#22411;&#65288;&#22914; JPG&#12289;PNG &#21644; GIF&#65289;&#32780;&#038;#1..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[42],"tuisongtax":[],"class_list":["post-673","my1js","type-my1js","status-publish","hentry","my1js2nav-xtywj"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=673"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=673"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=673"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}