


Imagecopyresampled は通常通り jpg をサンプリングして圧縮しますが、png はサンプリング後に 0 バイトになり、システムはそれを開くことができません。
imagecopyresampled は画像のサンプリングと jpg の圧縮には正常ですが、サンプリング後に png は 0 バイトになり、システムはそれを開くことができません。コードは次のとおりです。
$width = 200;$height = 200;header("Content-Type: {$data['file_type']}"); /// [file_type] => image/pnglist($width_orig, $height_orig) = getimagesize(".{$data['full_file_path']}"); //图片路径$ratio_orig = $width_orig/$height_orig;if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // 重新取样$image_p = imagecreatetruecolor($width, $height);$image = imagecreatefromjpeg(".{$data['full_file_path']}");$push = "image".$data['image_type'];imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);$push($image_p, $data['min_im'], 100);imagedestroy($image_p); imagedestroy($image);
jpg 形式のグラフィックス。サンプリング後は正常です。png のみです。 サンプリング圧縮は次のようになります。
ディスカッションへの返信 (解決済みの解決策)
完全なコードを投稿してください
png をフォーマットするときは、14 行目で imagecreatefrompng() を使用する必要があります
プログラムは判断しませんでしたか?
png をフォーマットするとき、14 行目は imagecreatefrompng() を使用する必要があります。
あなたのプログラムは判断を下しませんでしたか?
申し訳ありませんが、コードは次の条件に達していません。日付:
//重新对图片采样,平滑插入像素值 function upload_headimg($file='file') { $path = getpath(); if(empty($path)){ return ''; } $config['upload_path'] = $path; $config['allowed_types'] = 'jpg|jpeg|gif|png'; $config['max_size'] = '10240'; $config['file_name'] = 'wj_'.time().mt_rand(1000, 9999); $config['file_ext_tolower'] = TRUE; $CI = &get_instance(); $CI->load->library('upload', $config); $res = $CI->upload->do_upload($file); if($res){ $data = $CI->upload->data(); $path = ltrim($path,'.'); $data['full_file_path'] = $path.'/'.$data['file_name']; $data['min_im'] = '.'.$path.'/min'.$data['file_name']; $width = 200; $height = 200; header("Content-Type: {$data['file_type']}"); list($width_orig, $height_orig) = getimagesize(".{$data['full_file_path']}"); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // 重新取样 $image_p = imagecreatetruecolor($width, $height); $create_im ="imagecreatefrom".$data['image_type']; $image = $create_im(".{$data['full_file_path']}"); $push = "image".$data['image_type']; imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); $push($image_p, $data['min_im'], 100); imagedestroy($image_p); imagedestroy($image); //exit; return $data; }else{ return $CI->upload->display_errors(); } }
完全なコードを投稿してください
//重新对图片采样,平滑插入像素值 function upload_headimg($file='file') { $path = getpath(); if(empty($path)){ return ''; } $config['upload_path'] = $path; $config['allowed_types'] = 'jpg|jpeg|gif|png'; $config['max_size'] = '10240'; $config['file_name'] = 'wj_'.time().mt_rand(1000, 9999); $config['file_ext_tolower'] = TRUE; $CI = &get_instance(); $CI->load->library('upload', $config); $res = $CI->upload->do_upload($file); if($res){ $data = $CI->upload->data(); $path = ltrim($path,'.'); $data['full_file_path'] = $path.'/'.$data['file_name']; $data['min_im'] = '.'.$path.'/min'.$data['file_name']; $width = 200; $height = 200; header("Content-Type: {$data['file_type']}"); list($width_orig, $height_orig) = getimagesize(".{$data['full_file_path']}"); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } // 重新取样 $image_p = imagecreatetruecolor($width, $height); $create_im ="imagecreatefrom".$data['image_type']; $image = $create_im(".{$data['full_file_path']}"); $push = "image".$data['image_type']; imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); $push($image_p, $data['min_im'], 100); imagedestroy($image_p); imagedestroy($image); //exit; return $data; }else{ return $CI->upload->display_errors(); } }
40 行目で理由が見つかりました
$push($ image_p, $data['min_im'] , 100);
関数が imagepng の場合、3 番目のパラメーターの範囲は 0 ~ 9 です。
imagejpeg の場合、範囲は 0 ~ 100 です。
リスケールの提案についてjpeg の 0 ~ 99 の品質範囲を png の 0 ~ 9 の範囲に変換します。jpeg の場合は 99 が最小圧縮 (最大の品質)、png の場合は 9 が最大の圧縮 (品質は変わりません) であることに注意してください。
$push($image_p, $data['min_im'], 100);
関数が次の場合、3 番目のパラメーターの範囲は 0 ~ 9 です。 imagepng
imagejpeg 100 の場合、範囲は 0 ~

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











多くの場合、キーワードと追跡パラメーターで散らかった長いURLは、訪問者を阻止できます。 URL短縮スクリプトはソリューションを提供し、ソーシャルメディアやその他のプラットフォームに最適な簡潔なリンクを作成します。 これらのスクリプトは、個々のWebサイトにとって価値があります

2012年のFacebookによる有名な買収に続いて、Instagramはサードパーティの使用のために2セットのAPIを採用しました。これらはInstagramグラフAPIとInstagram Basic Display APIです。

Laravelは、直感的なフラッシュメソッドを使用して、一時的なセッションデータの処理を簡素化します。これは、アプリケーション内に簡単なメッセージ、アラート、または通知を表示するのに最適です。 データは、デフォルトで次の要求のためにのみ持続します。 $リクエスト -

これは、LaravelバックエンドとのReactアプリケーションの構築に関するシリーズの2番目と最終部分です。シリーズの最初の部分では、基本的な製品上場アプリケーションのためにLaravelを使用してRESTFUL APIを作成しました。このチュートリアルでは、開発者になります

Laravelは簡潔なHTTP応答シミュレーション構文を提供し、HTTP相互作用テストを簡素化します。このアプローチは、テストシミュレーションをより直感的にしながら、コード冗長性を大幅に削減します。 基本的な実装は、さまざまな応答タイプのショートカットを提供します。 Illuminate \ support \ facades \ httpを使用します。 http :: fake([[ 'google.com' => 'hello world'、 'github.com' => ['foo' => 'bar']、 'forge.laravel.com' =>

PHPクライアントURL(CURL)拡張機能は、開発者にとって強力なツールであり、リモートサーバーやREST APIとのシームレスな対話を可能にします。尊敬されるマルチプロトコルファイル転送ライブラリであるLibcurlを活用することにより、PHP Curlは効率的なexecuを促進します

顧客の最も差し迫った問題にリアルタイムでインスタントソリューションを提供したいですか? ライブチャットを使用すると、顧客とのリアルタイムな会話を行い、すぐに問題を解決できます。それはあなたがあなたのカスタムにより速いサービスを提供することを可能にします

2025 PHP Landscape Surveyは、現在のPHP開発動向を調査しています。 開発者や企業に洞察を提供することを目的とした、フレームワークの使用、展開方法、および課題を調査します。 この調査では、現代のPHP Versioの成長が予想されています
