golang怎么实现psd

Python020

golang怎么实现psd,第1张

您好,Go语言可以实现PSD,它是一种静态类型的编程语言,可以用来开发各种应用程序。Go语言拥有简单的语法,可以让开发者快速地实现PSD。Go语言支持多种编程范式,可以用来实现面向对象、函数式编程和过程式编程等。Go语言拥有强大的标准库,可以提供开发者丰富的功能,例如网络通信、文件系统操作、数据结构操作等。Go语言还支持多种编程框架,可以用来实现PSD。Go语言还支持多种编程工具,可以帮助开发者更快地实现PSD。总之,Go语言是一种强大的编程语言,可以帮助开发者快速实现PSD。

给你一个封装的图片处理的类吧!包含缩放和剪切功能!

构造方法只需要传递图片所在路径即可!对应方法及参数都有注释!

请给予最佳答案!!

<?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)

}

}

用ASP.jpeg组建,在服务器安装好后

以下为加水印代码

<%

Dim Jpeg

Set Jpeg = Server.CreateObject("Persits.Jpeg")

' 打开目标图片

Jpeg.Open Server.MapPath("images/1.jpg")'图片地址

' 添加文字水印

Jpeg.Canvas.Font.Color = &HFF0000' 红色

Jpeg.Canvas.Font.Family = "宋体"

Jpeg.Canvas.Font.Bold = True

Jpeg.Canvas.Print 10, 10, "水印内容:http://www.aspsub.cn/"

' 保存文件

Jpeg.Save Server.MapPath("images/1.jpg")

' 注销对象

Set Jpeg = Nothing

%>

你上传玩了后,获取到上传后的图片地址

存入一个变量中 然后吧 Server.MapPath("images/1.jpg")换成那个变量就行了