标题: 如何把多张jpg拼合成一张jpg长图(20元) [打印本页]
作者: bao9688 时间: 2022-3-13 09:52 标题: 如何把多张jpg拼合成一张jpg长图(20元)
例如:文件夹1--
图1.jpg
图2.jpg
图3.jpg
图4.jpg
结果:文件夹1--
图1.jpg
作者: Batcher 时间: 2022-3-13 11:08
回复 1# bao9688 - @echo off
- setlocal enabledelayedexpansion
- REM 处理该文件夹下的图片
- set "SrcFolder=D:\Test\Picture"
- REM 根据自己电脑实际情况设置ImageMagick的路径
- set "path=C:\Program Files\ImageMagick;%path%"
-
- if not exist "%SrcFolder%" (
- echo 找不到待处理的图片文件夹
- pause
- goto :eof
- )
- cd /d "%SrcFolder%"
- set "n=0"
- for /f "delims=" %%j in ('dir /b /a-d "*.jpg"') do (
- set /a n+=1
- )
- echo 正在处理文件夹:%SrcFolder% [包含!n!个jpg图片]
- montage.exe "*.jpg" -tile 1x!n! -geometry +10+10 "%temp%\拼接.jpg"
- del /f /q *.jpg
- move /y "%temp%\拼接.jpg" .
- pause
复制代码
ImageMagick官方下载地址:
https://imagemagick.org/script/download.php#windows
作者: Batcher 时间: 2022-3-13 11:09
回复 1# bao9688
http://bbs.bathome.net/thread-61893-1-1.html
这个帖子也是你的吗?
作者: 5i365 时间: 2022-3-13 11:51
我在国外找到一个系统相关的图像处理函数, 可以不用第三方组件, 感觉应该也可以实现, 编程水平有限, 期待高手能试试改一下- function Get-Image {
- <#
- .Synopsis
- Gets information about images.
-
- .Description
- Get-Image gets an object that represents each image file.
- The object has many properties and methods that you can use to edit images in Windows PowerShell.
-
- .Notes
- Get-Image uses Wia.ImageFile, a Windows Image Acquisition COM object to get image data.
- Then it uses the Add-Member cmdlet to add note properties and script methods to the object.
-
- The Resize script method uses the Add-ScaleFilter function. It has the following syntax:
- Resize ($width, $height, [switch]$DoNotPreserveAspectRation).
- Width and Height can be specified in pixels or percentages.
- For a description of these parameters, type "get-help Add-ScaleFilter –par *".
-
- The Crop script method uses the uses the Add-CropFilter function. It has the following syntax:
- Crop ([Double]$left, [Double]$top, [Double]$right, [Double]$bottom).
- All dimensions are measured in pixels.
- For a description of these parameters, type "get-help Add-CropFilter –par *".
-
- The FlipVertical, FlipHorizontal, RotateClockwise and RotateCounterClockwise script methods use the Add-RotateFlipFilter function.
- For a description of these parameters, type "get-help Add-RotateFlipFilter –par *".
-
- .Parameter File
- [Required] Specifies the image files. Enter the path and file name of an image file, such as $home\pictures\MyPhoto.jpg.
- You can also pipe one or more image files to Get-Image, such as those from Get-Item or Get-Childitem (dir).
-
- .Example
- Get-Image –file C:\myPics\MyPhoto.jpg
-
- .Example
- Get-ChildItem $home\Pictures -Recurse | Get-Image
-
- .Example
- (Get-Image –file C:\myPics\MyPhoto.jpg).resize(80, 120)
-
- .Example
- # Crops 8 pixels from the top of the image.
- $CatPhoto = Get-Image –file $home\Pictures\Cat.jpg
- $CatPhoto.crop(0,8,0,0)
-
- .Example
- $CatPhoto = Get-Image –file $home\Pictures\Cat.jpg
- $CatPhoto.flipvertical()
-
- .Example
- dir $home\pictures\Vacation*.jpg | get-image | format-table fullname, horizontalResolution, PixelDepth –autosize
-
- .Link
- "Image Manipulation in PowerShell": http://blogs.msdn.com/powershell/archive/2009/03/31/image-manipulation-in-powershell.aspx
- .Link
- Add-CropFilter
- .Link
- Add-ScaleFilter
- .Link
- Add-RotateFlipFilter
- .Link
- Get-ImageProperties
- #>
- param(
- [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)]
- [Alias('FullName')]
- [string]$file)
-
- process {
- $realItem = Get-Item $file -ErrorAction SilentlyContinue
- if (-not $realItem) { return }
- $image = New-Object -ComObject Wia.ImageFile
- try {
- $image.LoadFile($realItem.FullName)
- $image |
- Add-Member NoteProperty FullName $realItem.FullName -PassThru |
- Add-Member ScriptMethod Resize {
- param($width, $height, [switch]$DoNotPreserveAspectRatio)
- $image = New-Object -ComObject Wia.ImageFile
- $image.LoadFile($this.FullName)
- $filter = Add-ScaleFilter @psBoundParameters -passThru -image $image
- $image = $image | Set-ImageFilter -filter $filter -passThru
- Remove-Item $this.Fullname
- $image.SaveFile($this.FullName)
- } -PassThru |
- Add-Member ScriptMethod Crop {
- param([Double]$left, [Double]$top, [Double]$right, [Double]$bottom)
- $image = New-Object -ComObject Wia.ImageFile
- $image.LoadFile($this.FullName)
- $filter = Add-CropFilter @psBoundParameters -passThru -image $image
- $image = $image | Set-ImageFilter -filter $filter -passThru
- Remove-Item $this.Fullname
- $image.SaveFile($this.FullName)
- } -PassThru |
- Add-Member ScriptMethod FlipVertical {
- $image = New-Object -ComObject Wia.ImageFile
- $image.LoadFile($this.FullName)
- $filter = Add-RotateFlipFilter -flipVertical -passThru
- $image = $image | Set-ImageFilter -filter $filter -passThru
- Remove-Item $this.Fullname
- $image.SaveFile($this.FullName)
- } -PassThru |
- Add-Member ScriptMethod FlipHorizontal {
- $image = New-Object -ComObject Wia.ImageFile
- $image.LoadFile($this.FullName)
- $filter = Add-RotateFlipFilter -flipHorizontal -passThru
- $image = $image | Set-ImageFilter -filter $filter -passThru
- Remove-Item $this.Fullname
- $image.SaveFile($this.FullName)
- } -PassThru |
- Add-Member ScriptMethod RotateClockwise {
- $image = New-Object -ComObject Wia.ImageFile
- $image.LoadFile($this.FullName)
- $filter = Add-RotateFlipFilter -angle 90 -passThru
- $image = $image | Set-ImageFilter -filter $filter -passThru
- Remove-Item $this.Fullname
- $image.SaveFile($this.FullName)
- } -PassThru |
- Add-Member ScriptMethod RotateCounterClockwise {
- $image = New-Object -ComObject Wia.ImageFile
- $image.LoadFile($this.FullName)
- $filter = Add-RotateFlipFilter -angle 270 -passThru
- $image = $image | Set-ImageFilter -filter $filter -passThru
- Remove-Item $this.Fullname
- $image.SaveFile($this.FullName)
- } -PassThru
-
- } catch {
- Write-Verbose $_
- }
- }
- }
复制代码
作者: 5i365 时间: 2022-3-13 11:55
- #requires -version 2.0
- function Add-CropFilter {
- <#
- .Synopsis
- Creates a filter for cropping images.
-
- .Description
- The Add-CropFilter function adds a Crop image filter to a filter collection.
- It creates a new filter collection if none exists. An image filter is Windows Image Acquisition (WIA) concept.
- Each filter represents a change to an image.
-
- Add-CropFilter does not crop images; it just creates a crop filter.
- To crop an image, use the Crop method of the Get-Image function, which uses a crop filter that Add-CropFilter creates,
- or the Set-ImageFilter function, which applies the filters.
-
- All of the parameters of this function are optional.
- Without parameters, Add-CropFilter creates an image filter collection.
- Then it creates a crop filter that is not specific to an image and will not crop image content (values for the Left, Top, Right, and Bottom parameters are 0).
-
- .Parameter Filter
- Enter a filter collection (Wia.ImageProcess COM object).
- Each filter in the collection represents a unit of modification to a WiA ImageFile object.
- This parameter is optional. If you do not submit a filter collection, Add-CropFilter creates one for you.
-
- .Parameter Image
- Creates a crop filter for the specified image.
- Enter an image object, such as one returned by the Get-Image function.
- This parameter is optional.
- If you do not specify an image, Add-CropFilter creates a crop filter that is not image-specific.
-
- If you do not specify an image, you cannot specify percentage values (values less than 1) for the
- Left, Top, Right, or Bottom parameters.
-
- .Parameter Left
- Specifies the how much to crop from the left side of the image.
- The default value is zero (0). To specify pixels, enter a value greater than one (1).
- To specify a percentage, enter a value less than one (1), such as ".25".
- Percentages are valid only when the command includes the Image parameter.
-
- .Parameter Top
- Specifies the how much to crop from the top of the image.
- The default value is zero (0). To specify pixels, enter a value greater than one (1).
- To specify a percentage, enter a value less than one (1), such as ".25".
- Percentages are valid only when the command includes the Image parameter.
-
- .Parameter Right
- Specifies the how much to crop from the right side of the image.
- The default value is zero (0).
- To specify pixels, enter a value greater than one (1).
- To specify a percentage, enter a value less than one (1), such as ".25".
- Percentages are valid only when the command includes the Image parameter.
- .Parameter Bottom
- Specifies the how much to crop from the bottom of the image.
- The default value is zero (0).
- To specify pixels, enter a value greater than one (1).
- To specify a percentage, enter a value less than one (1), such as ".25".
- Percentages are valid only when the command includes the Image parameter.
-
- .Parameter Passthru
- Returns an object that represents the crop filter.
- By default, this function does not generate output.
-
- .Notes
- Add-CropFilter uses the Wia.ImageProcess object.
-
- .Example
- Add-CropFilter –right 45 –bottom 22 –passthru
-
- .Example
- $i = get-image .\Photo01.jpg
- Add-CropFilter –image $i –top .3 -passthru
-
- .Example
- C:\PS> $cf = Add-CropFilter –passthru
- C:\PS> ($cf.filters | select properties).properties | format-table Name, Value –auto
-
- Name Value
- ---- -----
- Left 0
- Top 0
- Right 45
- Bottom 22
- FrameIndex 0
-
-
- .Example
- $image = Get-Image .\Photo01.jpg
- $image = $image | Set-ImageFilter -filter (Add-CropFilter -Image $image -Left .1 -Right .1 -Top .1 -Bottom .1 -passThru) -passThru
- $image.SaveFile(".\Photo02.jpg")
- .Link
- Get-Image
- .Link
- Set-ImageFilter
- .Link
- Image Manipulation in PowerShell:
- http://blogs.msdn.com/powershell/archive/2009/03/31/image-manipulation-in-powershell.aspx
- .Link
- "ImageProcess object" in MSDN
- http://msdn.microsoft.com/en-us/library/ms630507(VS.85).aspx
- .Link
- "Filter Object" in MSDN
- http://msdn.microsoft.com/en-us/library/ms630501(VS.85).aspx
- .Link
- "How to Use Filters" in MSDN
- http://msdn.microsoft.com/en-us/library/ms630819(VS.85).aspx
- #>
- param(
- [Parameter(ValueFromPipeline=$true)]
- [__ComObject]
- $filter,
-
- [__ComObject]
- $image,
-
- [Double]$left,
- [Double]$top,
- [Double]$right,
- [Double]$bottom,
-
- [switch]$passThru
- )
-
- process {
- if (-not $filter) {
- $filter = New-Object -ComObject Wia.ImageProcess
- }
- $index = $filter.Filters.Count + 1
- if (-not $filter.Apply) { return }
- $crop = $filter.FilterInfos.Item("Crop").FilterId
- $isPercent = $true
- if ($left -gt 1) { $isPercent = $false }
- if ($top -gt 1) { $isPercent = $false }
- if ($right -gt 1) { $isPercent = $false }
- if ($bottom -gt 1) { $isPercent = $false }
- $filter.Filters.Add($crop)
- if ($isPercent -and $image) {
- $filter.Filters.Item($index).Properties.Item("Left") = $image.Width * $left
- $filter.Filters.Item($index).Properties.Item("Top") = $image.Height * $top
- $filter.Filters.Item($index).Properties.Item("Right") = $image.Width * $right
- $filter.Filters.Item($index).Properties.Item("Bottom") = $image.Height * $bottom
- } else {
- $filter.Filters.Item($index).Properties.Item("Left") = $left
- $filter.Filters.Item($index).Properties.Item("Top") = $top
- $filter.Filters.Item($index).Properties.Item("Right") = $right
- $filter.Filters.Item($index).Properties.Item("Bottom") = $bottom
- }
- if ($passthru) { return $filter }
- }
- }
复制代码
作者: 5i365 时间: 2022-3-13 11:57
复制代码
作者: bao9688 时间: 2022-3-13 12:15
回复 2# Batcher
老师,这个第三方插件咋用啊
作者: Batcher 时间: 2022-3-13 12:26
回复 7# bao9688
先下载,再安装,然后用2楼的BAT脚本。
作者: Batcher 时间: 2022-3-13 12:33
回复 7# bao9688
其他类似的图片处理操作:
http://bbs.bathome.net/thread-60605-1-1.html#pid251524
作者: bao9688 时间: 2022-3-13 12:37
回复 9# Batcher
REM 根据自己电脑实际情况设置ImageMagick的路径
set "path=C:\Program Files\ImageMagick;%path%"
我不明白的是这个地方怎么设置。已经安装好了,安装路径是"D:\图片处理\ImageMagick-7.1.0-Q16-HDRI"
作者: bao9688 时间: 2022-3-13 12:38
回复 9# Batcher
正在处理文件夹:C:\Users\Administrator\Desktop\测试\1 [包含2个jpg图片]
'montage.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
系统找不到指定的文件。
请按任意键继续. . .
作者: Batcher 时间: 2022-3-13 12:44
回复 10# bao9688
ImageMagick你安装到哪个路径下面了?
作者: bao9688 时间: 2022-3-13 12:46
回复 12# Batcher
安装路径是"D:\图片处理\ImageMagick-7.1.0-Q16-HDRI"
作者: Batcher 时间: 2022-3-13 12:53
回复 13# bao9688
set "path=D:\图片处理\ImageMagick-7.1.0-Q16-HDRI;%path%"
作者: Batcher 时间: 2022-3-13 13:08
回复 13# bao9688
如果还是那个报错,请检查你的 D:\图片处理\ImageMagick-7.1.0-Q16-HDRI 文件夹下是否有:montage.exe
如果仍有问题,请参考Q-01观察一下哪行代码在报错以及详细的报错信息:
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
如需上传截图,请用图床:
http://bbs.bathome.net/thread-60985-1-1.html
继续回帖讨论即可,不用给我发私信,谢谢。
作者: 访客9688 时间: 2022-3-13 13:40
回复 15# Batcher
每日回帖次数上限了,注册了个临时账号回复您,
按你的提供的第三方插件网址,我下载了前两个版本都没有montage.exe文件
截图文件地址https://imgtu.com/i/bbhUNd 您看看下载那个版本?
报错结果:
正在处理文件夹:C:\Users\Administrator\Desktop\测试\1 [包含2个jpg图片]
'montage.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
系统找不到指定的文件。
请按任意键继续. .
作者: Batcher 时间: 2022-3-13 16:09
回复 16# 访客9688
下载这个试过吗?
ImageMagick-7.1.0-portable-Q16-HDRI-x64.zip
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |