Const pxsize = 255 '仕上がりのピクセルサイズ(誤差あり)
Set app = CreateObject("Illustrator.Application.2")
Set jpgoption = CreateObject("Illustrator.ExportOptionsJPEG.2")
With jpgoption
.AntiAliasing = True 'default
.ArtBoardClipping = False 'default
.BlurAmount = 0 'ぼかし
.Matte = False
.QualitySetting = 100
End With
Set white = CreateObject("Illustrator.RGBColor.2")
white.Red = 255
white.Green = 255
white.Blue = 255
Set objArgs = WScript.Arguments
For i = 0 To objArgs.Count - 1
Set doc = app.Open(objArgs(i))
'そのまま計算するとなぜかエラーになるので一旦変数に代入
bds = doc.VisibleBounds
theX = pxsize * 100 / (bds(2) - bds(0)) '右-左
theY = pxsize * 100 / (bds(1) - bds(3)) '天-地
If theX >= theY Then tmp = theY
If theX < theY Then tmp = theX
For j = 1 To doc.PageItems.Count 'PageItemはCSでも使える
With doc.PageItems(j)
If (.PageItemType > 3 Or .PageItemType = 2) Then
'PageItems(j)がaiCompoundPathItem(id=1)や
' aiGroupItem(id=3)だと2重3重に縮小される
.Hidden = False
.Locked = False
.Resize tmp, tmp, True, True, True, True, tmp, 1
'1 = aiTransformDocumentOrigin
End If
End With
Next 'j
bds = doc.VisibleBounds
theX = (bds(2) + bds(0)) / 2
theY = (bds(1) + bds(3)) / 2
point1 = Array(theX - pxsize / 2, theY - pxsize / 2)
point2 = Array(theX - pxsize / 2, theY + pxsize / 2)
point3 = Array(theX + pxsize / 2, theY + pxsize / 2)
point4 = Array(theX + pxsize / 2, theY - pxsize / 2)
bkline = Array(point1, point2, point3, point4, point1)
Set back = doc.PathItems.Add
back.SetEntirePath bkline
back.Filled = True
back.Stroked = False
back.FillColor = white
back.ZOrder (4) '4 = aiSendToBack
'拡張子は勝手につけ変えてくれる
doc.Export objArgs(i), 1, jpgoption '1 = aiJPEG
doc.Close 2 '2 = aiDoNotSaveChanges
Next 'i
'app.Quit
|