phpbmp支持,phpfmp

本文目錄一覽:

PHP怎麼轉換圖片格式?

用下面代碼(PHP必須支持GD庫)

$input=上傳的BMP文件名

$output=要存的jpeg文件名

$image=imagecreatefromwbmp($input);

imagejpeg($image,$output);

imagedestroy($image);

unlink($input);

用GD庫還可以加水印、改大小等,網上都有,一搜就行。我是按照PHP手冊

你可以去後盾人平台看一下,裡面的東西不錯

我這有個已經實現了php上傳圖片的功能的類,但是現在還要給上傳的每張圖片加水印,請高手幫忙……

給你一個封裝的圖片處理的類吧!包含縮放和剪切功能!

構造方法只需要傳遞圖片所在路徑即可!對應方法及參數都有注釋!

請給予最佳答案!!

?php

class Img{

private $path;

//構造方法,初始化圖片信息

function __construct($path=’./imgs/’){

$this-path=rtrim($path,’/’).’/’;

}

/**

* 對圖片進行縮放

* 參數對應:文件名 縮放後寬度 縮放後高度 縮放後圖片名前綴

*/

function thumb($name,$width,$height,$pre=”th_”){

if(file_exists($this-path.$name)){

$imgInfo=$this-getInfo($name);

$img=$this-getImg($name,$imgInfo);

$newSize=$this-getNewSize($name,$width,$height,$imgInfo);

$newImg=$this-getNewInfo($img,$newSize,$imgInfo);

return $this-createNewImage($newImg, $pre.$name, $imgInfo);

}else{

echo ‘圖片’.$this-path.$name.’不存在,請檢查文件名及路徑是否填寫正確’;

}

}

//輔助圖片處理,獲取圖片的寬、高、類型屬性

private function getInfo($name){

$temp=getImageSize($this-path.$name);

$imgInfo[‘width’]=$temp[0];

$imgInfo[‘height’]=$temp[1];

$imgInfo[‘type’]=$temp[2];

return $imgInfo;

}

//輔助圖片處理,獲取創建的圖片資源

private function getImg($name,$imgInfo){

$src=$this-path.$name;

switch($imgInfo[‘type’]){

case 1:

$img=imagecreatefromgif($src);

break;

case 2:

$img=imagecreatefromjpeg($src);

break;

case 3:

$img=imagecreatefrompng($src);

break;

}

return $img;

}

//輔助圖片處理,獲取創建的圖片資源

private function getNewSize($name,$width,$height,$imgInfo){

$newSize[‘width’]=$imgInfo[‘width’];

$newSize[‘height’]=$imgInfo[‘height’];

if($width$imgInfo[‘width’]){

$newSize[‘width’]=$width;

}

if($height$imgInfo[‘height’]){

$newSize[‘height’]=$height;

}

if($imgInfo[“width”]*$newSize[“width”] $imgInfo[“height”] * $newSize[“height”]){

$newSize[“height”]=round($imgInfo[“height”]*$newSize[“width”]/$imgInfo[“width”]);

}else{

$newSize[“width”]=round($imgInfo[“width”]*$newSize[“height”]/$imgInfo[“height”]);

}

print_r($newSize);

return $newSize;

}

//輔助圖片處理,獲取縮放的圖片資源

private function getNewInfo($img,$newSize,$imgInfo){

$newImg=imagecreatetruecolor($newSize[‘height’],$newSize[‘height’]);

$otsc=imagecolortransparent($img);

if($otsc =0 $otsc = imagecolorstotal($img)){

$tran=imagecolorsforindex($img, $otsc);

$newt=imagecolorallocate($newImg, $tran[“red”], $tran[“green”], $tran[“blue”]);

imagefill($newImg, 0, 0, $newt);

imagecolortransparent($newImg, $newt);

}

imagecopyresized($newImg, $img, 0, 0, 0, 0, $newSize[“width”], $newSize[“height”], $imgInfo[“width”], $imgInfo[“height”]);

imagedestroy($img);

return $newImg;

}

//輔助圖片處理,創建新的圖片

private function createNewImage($newImg, $newName, $imgInfo){

switch($imgInfo[“type”]){

case 1://gif

$result=imageGif($newImg, $this-path.$newName);

break;

case 2://jpg

$result=imageJPEG($newImg, $this-path.$newName);

break;

case 3://png

$return=imagepng($newImg, $this-path.$newName);

break;

}

imagedestroy($newImg);

return $newName;

}

/**

* 對圖片加水印

* 參數對應:需水印圖片 水印圖片 加水印後圖片名前綴

*/

function waterMark($name,$wname,$pre=”wa_”){

if(file_exists($this-path.$name)){

if(file_exists($this-path.$wname)){

$info=$this-getInfo($name);

$winfo=$this-getInfo($wname);

if($p=$this-getPosition($info,$winfo)){

$img=$this-getImg($name,$info);

$wImg=$this-getImg($wname,$winfo);

imagecopy($img, $wImg, $p[“x”], $p[“y”], 0, 0, $winfo[“width”], $winfo[“height”]);

imagedestroy($wImg);

return $this-createNewImage($img,$pre.$name,$info);

}else{

echo ‘水印圖片尺寸大於原圖片尺寸’;

}

}else{

echo ‘水印圖片’.$this-path.$wname.’不存在,請檢查文件名及路徑是否填寫正確’;

}

}else{

echo ‘圖片’.$this-path.$name.’不存在,請檢查文件名及路徑是否填寫正確’;

}

}

//輔助圖片處理,獲取水印圖片應處坐標

private function getPosition($info,$winfo){

if($info[‘width’]$winfo[‘width’]||$info[‘height’]$winfo[‘height’]){

return false;

}

$x=$info[‘width’]-$winfo[‘width’];

$y=$info[‘height’]-$winfo[‘height’];

return array(‘x’=$x,’y’=$y);

}

/**

* 圖片剪切函數

* 對應參數:原圖片 X坐標 Y坐標 寬度 高度

*/

function cut($name,$x,$y,$width,$height,$pre=’cx_’){

$imgInfo=$this-getInfo($name);

$img=$this-getImg($name,$imgInfo);

$newImg=imagecreatetruecolor($width,$height);

imagecopyresampled($newImg,$img,0,0,$x,$y,$width,$height,$width,$height);

return $this-createNewImage($newImg, $pre.$name, $imgInfo);

}

}

php上傳bmp圖片類型問題

imagecreatefromwbmp() 這個函數 不能針對bmp文件操作,因為兩個根本不是什麼相似的文件類型。

php5版本還沒有 imagecreatefrombmp() 這個函數(是bmp不是wbmp)

所以無法創建bmp圖像。

所以那啥,要麼你自己寫一個imagecreatefrombmp()進行擴展。

要麼就源文件上傳。

如何在php中打開bmp格式的圖片

如果擴展名不是故意該的話php是一個腳本語言文件。你可以用記事本打開看看裡面 如果確認是圖片 你可以把php改成jpg或png或bmp試試

bmp是什麼格式?bmp文件格式怎麼打開?

它採用位映射存儲格式,除了圖像深度可選以外,不採用其他任何壓縮,因此,BMP文件所佔用的空間很大。BMP文件的圖像深度可選lbit、4bit、8bit及24bit。BMP文件存儲數據時,圖像的掃描方式是按從左到右、從下到上的順序。

由於BMP文件格式是Windows環境中交換與圖有關的數據的一種標準,因此在Windows環境中運行的圖形圖像軟體都支持BMP圖像格式。

典型的BMP圖像文件由四部分組成:

1:點陣圖頭文件數據結構,它包含BMP圖像文件的類型、顯示內容等信息;

2:點陣圖信息數據結構,它包含有BMP圖像的寬、高、壓縮方法,以及定義顏色等信息;

3:調色板,這個部分是可選的,有些點陣圖需要調色板,有些點陣圖,比如真彩色圖(24位的BMP)就不需要調色板;

4:點陣圖數據,這部分的內容根據BMP點陣圖使用的位數不同而不同,在24點陣圖中直接使用RGB,而其他的小於24位的使用調色板中顏色索引值。

bmp文件怎麼打開?

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/259571.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-15 16:29
下一篇 2024-12-15 16:29

發表回復

登錄後才能評論