2. 問題の分析と解決策
【PHPサムネイル部門】携帯電話の写真のサムネイルが生成できない問題と解決策
[原文、転載禁止]
1. 外観の問題
ここ数日、携帯電話で写真をアップロードしてサムネイルを切り出すインターフェイスをテストしていましたが、生成されたサムネイルが完全に真っ黒であることがわかりました。 :-(
その後、テストのためにこのサムネイルリストを取り出したところ、携帯電話で撮影した写真ではサムネイルを処理できないことがわかりました...
2. 問題分析と解決策
グループで相談した結果、png画像にはファイル形式の判定に問題が発生する可能性があることが分かりました。透明レイヤーなので直接jpgファイルに変換することはできず、携帯で撮った写真の拡張子は
なので、結論としては携帯で撮った写真です。 という名前の PNG 画像の拡張子は
です。3. サムネイルを生成します。 class
//获取真实的图片类型 list($width, $height, $type, $attr) = getimagesize($this->sur_file); switch($type) { case 1 : $img_type = 'gif'; break; case 2 : $img_type = 'jpeg'; break; case 3 : $img_type = 'png'; break; case 15 : $img_type = 'wbmp'; break; default : return false; }
サムネイルを生成するために変更されたクラスを修正のために以下に掲載します~
/** * php生成缩略图类 * 修改者 点点细雨 * 文章出处 : http://blog.csdn.net/diandianxiyu_geek * 2014-07-23 解决了图片类型不能正常识别的问题 */class thumb { public $sur_file; //读取的原图片 public $des_file; //生成目标图片 public $tem_file; //临时图片 public $tag; //缩略标签 0,默认,按固定的高宽生成 1,按比列或固定最大长度生成 -1,按某个宽度或某个高度缩小 public $resize_width; //$tag为0时,目标文件宽 public $resize_height; //$tag为0时,目标文件高 public $sca_max; //$tag为1时,<0$sca_max<1时为缩小比例;$sca_max>1时为最大长度(高或宽之中的最大值) public $type; //图片类型 public $width; //原图片宽 public $height; //原图片高 public $size; //原图大小 //构造函数 public function __construct($surpic, $reswid, $reshei, $despic, $mark, $scamax) { $this->sur_file = $surpic; $this->resize_width = $reswid; $this->resize_height = $reshei; $this->tag = $mark; $this->sca_max = $scamax; list($width, $height, $type, $attr) = getimagesize($this->sur_file); switch ($type) { case 1 : $img_type = 'gif'; break; case 2 : $img_type = 'jpeg'; break; case 3 : $img_type = 'png'; break; case 15 : $img_type = 'wbmp'; break; default : return false; } $this->type = $img_type; //获取图片类型 $this->init_img(); //初始化图片 $this->des_file = $despic; //目标图片地址 $this->width = $width; $this->height = $height; $this->size = filesize($surpic); $this->new_img(); imagedestroy($this->tem_file); } //图片初始化函数 private function init_img() { if ($this->type == 'jpeg') { $this->tem_file = imagecreatefromjpeg($this->sur_file); } elseif ($this->type == 'jpg') { $this->tem_file = imagecreatefromjpeg($this->sur_file); } elseif ($this->type == 'gif') { $this->tem_file = imagecreatefromgif($this->sur_file); } elseif ($this->type == 'png') { $this->tem_file = imagecreatefrompng($this->sur_file); } elseif ($this->type == 'bmp') { $this->tem_file = imagecreatefrombmp($this->sur_file); //bmp.php中包含 } } //图片生成函数 private function new_img() { $ratio = ($this->width) / ($this->height); //原图比例 $resize_ratio = ($this->resize_width) / ($this->resize_height); //缩略后比例 $newimg = imagecreatetruecolor($this->resize_width, $this->resize_height); //生成新图片 imagealphablending($newimg, false); //这里很重要,意思是不合并颜色,直接用$img图像颜色替换,包括透明色; imagesavealpha($newimg, true); if ($this->tag == 0) { //按固定高宽截取缩略图 $newimg = imagecreatetruecolor($this->resize_width, $this->resize_height); //生成新图片 if ($ratio >= $resize_ratio) {//即等比例下,缩略图的高比原图长,因此高不变 imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->resize_width, $this->resize_height, (($this->height) * $resize_ratio), $this->height); } elseif ($ratio < $resize_ratio) {//即等比例下,缩略图的宽比原图长,因此宽不变 imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width) / $resize_ratio)); } } elseif ($this->tag == 1) { //按固定比例或最大长度缩小 if ($this->sca_max < 1) { //按比例缩小 $newimg = imagecreatetruecolor((($this->width) * ($this->sca_max)), (($this->height) * ($this->sca_max))); //生成新图片 imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, (($this->width) * ($this->sca_max)), (($this->height) * ($this->sca_max)), $this->width, $this->height); } elseif ($this->sca_max > 1) { //按某个最大长度缩小 if ($ratio >= 1) { //宽比高长 $newimg = imagecreatetruecolor($this->sca_max, ($this->sca_max / $ratio)); //生成新图片 imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->sca_max, ($this->sca_max / $ratio), $this->width, $this->height); } else { $newimg = imagecreatetruecolor(($this->sca_max * $ratio), $this->sca_max); //生成新图片 imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, ($this->sca_max * $ratio), $this->sca_max, $this->width, $this->height); } } } elseif ($this->tag == -1) { //按某个宽度或某个高度缩小 if ($resize_ratio >= 1) {//新高小于新宽,则图片按新宽度缩小 $newimg = imagecreatetruecolor($this->resize_width, ($this->resize_width / $ratio)); //生成新图片 imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->resize_width, ($this->resize_width / $ratio), $this->width, $this->height); } elseif ($resize_ratio < 1) {//新宽小于新高,则图片按新高度缩小 $newimg = imagecreatetruecolor(($this->resize_height * $ratio), $this->resize_height); //生成新图片 imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, ($this->resize_height * $ratio), $this->resize_height, $this->width, $this->height); } } //输出新图片 if ($this->type == 'jpeg' || $this->type == 'jpg') { imagejpeg($newimg, $this->des_file); } elseif ($this->type == 'gif') { imagegif($newimg, $this->des_file); } elseif ($this->type == 'png') { imagepng($newimg, $this->des_file); } elseif ($this->type == 'bmp') { imagebmp($newimg, $this->des_file); //bmp.php中包含 } }#function new_img() end}

ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

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

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

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

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

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

ホットトピック











多くのユーザーはスマートウォッチを選ぶときにファーウェイブランドを選択しますが、その中でもファーウェイ GT3pro と GT4 は非常に人気のある選択肢であり、多くのユーザーはファーウェイ GT3pro と GT4 の違いに興味を持っています。 Huawei GT3pro と GT4 の違いは何ですか? 1. 外観 GT4: 46mm と 41mm、材質はガラスミラー + ステンレススチールボディ + 高解像度ファイバーバックシェルです。 GT3pro: 46.6mm および 42.9mm、材質はサファイアガラス + チタンボディ/セラミックボディ + セラミックバックシェルです。 2. 健全な GT4: 最新の Huawei Truseen5.5+ アルゴリズムを使用すると、結果はより正確になります。 GT3pro: ECG 心電図と血管と安全性を追加

Windows 11 で Snipping Tool が機能しない理由 問題の根本原因を理解すると、適切な解決策を見つけるのに役立ちます。 Snipping Tool が正しく動作しない主な理由は次のとおりです。 フォーカス アシスタントがオンになっている: これにより、Snipping Tool が開かなくなります。破損したアプリケーション: 起動時にスニッピング ツールがクラッシュする場合は、破損している可能性があります。古いグラフィック ドライバー: 互換性のないドライバーは、スニッピング ツールに干渉する可能性があります。他のアプリケーションからの干渉: 実行中の他のアプリケーションが Snipping Tool と競合する可能性があります。証明書の有効期限が切れています: アップグレード プロセス中のエラーにより、この問題が発生する可能性があります。これらの簡単な解決策は、ほとんどのユーザーに適しており、特別な技術知識は必要ありません。 1. Windows および Microsoft Store アプリを更新する

Vue で画像を圧縮してフォーマットするにはどうすればよいですか?フロントエンド開発では、画像を圧縮してフォーマットする必要が生じることがよくあります。特にモバイル開発では、ページの読み込み速度を向上させ、ユーザーのトラフィックを節約するために、画像を圧縮してフォーマットすることが重要です。 Vue フレームワークでは、いくつかのツール ライブラリを使用して画像を圧縮およびフォーマットできます。 compressor.js ライブラリを使用した圧縮 compressor.js は画像を圧縮するための JavaS です。

HTML5 では、width は幅を意味します。width 属性は要素のコンテンツ領域の幅を定義します。コンテンツ領域の外側に内側のマージン、境界線、および外側のマージンを追加できます。「要素 {width: value}」を設定するだけで済みます。要素。

パート 1: 最初のトラブルシューティング手順 Apple のシステムステータスを確認する: 複雑な解決策を掘り下げる前に、基本から始めましょう。問題はデバイスにあるのではなく、Apple のサーバーがダウンしている可能性があります。 Apple のシステム ステータス ページにアクセスして、AppStore が適切に動作しているかどうかを確認してください。問題があれば、Apple が修正してくれるのを待つしかありません。インターネット接続を確認します。「AppStore に接続できません」問題は接続不良が原因である場合があるため、安定したインターネット接続があることを確認してください。 Wi-Fi とモバイル データを切り替えるか、ネットワーク設定をリセットしてみてください ([一般] > [リセット] > [ネットワーク設定のリセット] > [設定])。 iOS バージョンを更新します。

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

この記事は、vue ソース コードを解釈するのに役立ち、これを使用して Vue2 のさまざまなオプションのプロパティにアクセスできる理由を紹介します。

画像のサイズ変更、切り抜き、回転、反転。まず、元の画像は、次のように、インターネットからダウンロードした異なるサイズの 10 枚の画像です: 操作 1: サイズ変更 画像を同じサイズ (320,240) にサイズ変更します。 fromPILimportImageimporttorchvision.transformsastransforms# PIL を使用します。画像とresizeefResizeImage():ifnotos.path.exists(rdir):os.makedirs(rdir)foriinrange(10):im=Image.open(d)を読み込むライブラリ
