DESCRIPTION
Use to convert and resize (downsample only) comic books from one format to another. It recognizes standard comic book files: .cbr (RAR), .cbz (ZIP) and .cb7 (7z) for both import and export. This should work with most of the comic books in the wild. If dealing with some other format, like PDF comic books, I recommend using ComicRack (http://comicrack.cyolito.com/) to convert first to classic .cbr, .cbz or .cb7.
FEATURES
- Dialog window for options preselection
- Plethora of predefined screen resolutions for:
- Android tablets and phones
- iPhones and iPads
- Custom size
- Resize orientation modes: Auto / Force Portrait / Force Landscape
- Repack only option (skip resizing images)
- Conversion image quality can be changed
- Export to either home source or destination lister
- Choose either Windows default or your own temporary folder, such as RAM disk for maximum convenience selection survives even system reboot)
- Output formats: .cb7 (default, recommended), .cbr, .cbz
- For lots of files in queue, a file may be automatically deselected once this file conversion is complete (option)
- Import file may have folders structure depth at will, the program tries to get to the bottom of it to find where the image files actually are
- Provides logging so you can keep track via script log
SHOWCASE VIDEO
INSTALLATION
Use either provided button (.dcf) or attached VBScript code with dialog resource (please scroll down).
CBx to CBx Comic Book Convert Resize v1.50.dcf (31.3 KB)
WHY
...this program, since ComicRack can also do it?
Well, despite the fact that Directory Opus is more than ideal tool to do it, I wouldn't probably bother if I could find decent software to do it. The fact is that ComicRack has silently abrupted converting, due to some mysterious I/O errors. It might be that it didn't not like my computer being used whilst it was converting the files.
HISTORY
v1.00: 2017-01-28 Initial Release
v1.10: 2017-01-29 Ability to set custom temp folder such as RAM disk
v1.21: 2017-01-31 Ability to save TEMP folder for next script call (first official release)
v1.30: 2017-02-13
New user options:
(1) Do Not Resize
(2) Deselect file after conversion
Enforced error prevention:
(1) Make sure no protected files from deletion dialog pops-out
(2) Removes spaces before extension to prevent errors
v1.40: 2017-02-15
Added quality change option. Auto mode is now default.
v1.50: 2019-02-05 Small bugfix - Output format now correctly displays 7Z (.cb7)
METHOD
The script is programmed using VBScript over powerful Directory Opus objects. This is my first Directory Opus script. I believe it could be done better but I'm pretty satisfied with the final result, especially since it took me two days from v0.0 to v1.0. However, all suggestions and criticisms are more than welcomed.
SCRIPT CODE
Is heavily commented. I believe it will help you great deal if you are DOpus script beginner like I was when I started with this little project.
CBx-TO-CBx SCRIPT CODE
@script VBScript
'--------------------------------------------------------------------------------
' CBx to CBx
' This script converts and resizes comic book files
' Includes versatile dialog for maximal user friendlines
' Date: 2017-01-31
' Author: Dalibor Puljiz, Croatia
' Thanks:
' - Directory Opus developers for the greatest software
' - @Playful for providing great insight on DOpus object
' through his first conversion script: 'cbr to cbz'
' https://resource.dopus.com/t/button-cbr-to-cbz/23170
'Forum support:
' https://resource.dopus.com/t/button-comic-book-cbx-to-cbx-convert-resize/24719
'History:
' v1.00: 2017-01-28 Initial Release
' v1.10: 2017-01-29 Ability to set custom temp folder such as RAM disk
' v1.21: 2017-01-31 Ability to save TEMP folder for next script call (first official release)
' v1.30: 2017-02-13
' New user options:
' (1) Do Not Resize
' (2) Deselect file after conversion
' Enforced error prevention:
' (1) Make sure no protected files from deletion dialog pops-out
' (2) Removes spaces before extension to prevent errors
' v1.40: 2017-02-15
' Added quality change option. Auto mode is now default.
' v1.50: 2019-02-05 Small bugfix - Output format now correctly displays 7Z (.cb7)
'--------------------------------------------------------------------------------
Option Explicit
Const WindowsFolder = 0
Const SystemFolder = 1
Const TemporaryFolder = 2
Function OnClick(ClickData)
Dim dlgO: Dim msgD
Dim ixList: Dim ixLabel: Dim ixXPos: Dim ixWPos: Dim ixHPos
Dim lngNewWidth: Dim lngNewHeight: Dim strResizeMode
Dim blnUseTempFolder: Dim strTmpF
Dim blnDeselectAfterConversion
Dim strUseSD
Dim fsT: Dim strOutFormat
Dim strTgtLst
Dim currentFile: Dim retF
Dim cmdDS
'Pickup where you left off
'Temp folder: Windows %Temp% folder recommended, most likely SSD disk anyway)
'However if you use some RAM disk (such as AMD RAM Disk), you may wish to keep it on
Set fsT = CreateObject("Scripting.FileSystemObject")
If DOpus.vars("CBxToCBxTempFolder").Exists Then
strTmpF = DOpus.vars.get("CBxToCBxTempFolder")
Else
strTmpF = CStr(fsT.GetSpecialFolder(TemporaryFolder))
DOpus.vars.set("CBxToCBxTempFolder")= strTmpF
DOpus.vars("CBxToCBxTempFolder").Persist = True
End If
If DOpus.vars("CBxToCBxUseWindowsTemp").Exists Then
blnUseTempFolder = CBool(DOpus.vars.get("CBxToCBxUseWindowsTemp"))
Else
blnUseTempFolder = True
DOpus.vars.set("CBxToCBxUseWindowsTemp") = blnUseTempFolder
DOpus.vars("CBxToCBxUseWindowsTemp").Persist = True
End If
'Initialize dialog box using resource template
Set dlgO = ClickData.Func.Dlg
dlgO.template = "dlgSetFileSize"
dlgO.detach = True
dlgO.Show
'Set defaults
'Resolution: 800×1280
dlgO.Control("lstResolution").Value = 1
lngNewHeight = 1280
lngNewWidth = 800
strResizeMode = "Auto"
dlgO.Control("chkOrientationMode").Value = 2 'Auto
dlgO.Control("chkOrientationMode").Label = "Auto per image"
'Outptut format: cb7 and Auto dimension
dlgO.Control("cbxOutputFormat").Value = 0 ' .cb7 (cbz)
strOutFormat = ".cb7"
'Lister: Destination
strUseSD = "destin"
dlgO.Control("radUseSource").Value = False
dlgO.Control("radUseDestination").Value = True
'Temp section
dlgO.Control("btnSelectFolder").Enabled = Not blnUseTempFolder
dlgO.Control("tbxCustomTempFolder").Value = strTmpF
dlgO.Control("radWindowsTemp").Value = blnUseTempFolder
dlgO.Control("radCustomTempFolder").Value = Not blnUseTempFolder
blnDeselectAfterConversion = False
'Keep running in detached mode so we can run events asynchronously
Do
Set msgD = dlgO.GetMsg()
'Preliminary pre-setup orientation modes, so later change may run smoothly
If msgD.Control = "chkOrientationMode" Then
Select Case dlgO.Control("chkOrientationMode").Value
Case 0
strResizeMode = "Landscape"
dlgO.Control("chkOrientationMode").Label = "Force Landscape"
Case 1
strResizeMode = "Portrait"
dlgO.Control("chkOrientationMode").Label = "Force Portrait"
Case 2
strResizeMode = "Auto"
dlgO.Control("chkOrientationMode").Label = "Auto per image"
End Select
End If
'Check everything
Select Case msgD.Control
Case "chkDoNotResize"
dlgO.Control("chkOrientationMode").Enabled = Not (dlgO.Control("chkDoNotResize").Value)
If dlgO.Control("chkDoNotResize").Value Then strResizeMode = "Do Not Resize"
Case "lstResolution", "chkOrientationMode", "imgRWidth", "imgRHeight"
'Get actual content label so to skip hard translate side-side coding
ixList = dlgO.Control("lstResolution").Value
ixLabel = dlgO.Control("lstResolution").GetItemAt(ixList).name 'ie: Android Tablet: 2560 × 1440
If InStr(1,ixLabel,"Custom",1) = 0 Then
dlgO.Control("imgRWidth").Enabled = False
dlgO.Control("imgRHeight").Enabled = False
ixXPos = InStr(1,ixLabel,"×") 'W×H separated by ×
ixWPos = InStrRev(ixLabel," ",ixXPos-2) 'find first space backwards
ixHPos = InStr(ixXPos+2,ixLabel," ") 'find next space forward
If ixHPos = 0 Then ixHPos = Len(ixLabel) 'if not found assume max string length
Select Case strResizeMode
Case "Portrait", "Auto"
lngNewHeight = Mid(ixLabel,ixWPos+1,(ixXPos-ixWPos-2))
lngNewWidth = Mid(ixLabel,ixXPos+2,(ixHPos-ixXPos-1))
Case "Landscape"
lngNewWidth = Mid(ixLabel,ixWPos+1,(ixXPos-ixWPos-2))
lngNewHeight = Mid(ixLabel,ixXPos+2,(ixHPos-ixXPos-1))
End Select
Else
dlgO.Control("imgRWidth").Enabled = True
dlgO.Control("imgRHeight").Enabled = True
Select Case "strResizeMode"
Case "Portrait", "Auto"
lngNewHeight = dlgO.Control("imgRWidth").Value
lngNewWidth = dlgO.Control("imgRHeight").Value
Case "Landscape"
lngNewWidth = dlgO.Control("imgRWidth").Value
lngNewHeight = dlgO.Control("imgRHeight").Value
End Select
End if
dlgO.Control("tbxNotifySelected").Value = "Exporting to WH " & lngNewWidth & "×" & lngNewHeight & " (" & strResizeMode & ")"
'Get other dialog options
Case "radUseSource", "radUseDestination"
Select Case msgD.Control
Case "radUseSource": strUseSD = "source"
Case "radUseDestination": strUseSD = "destin"
End Select
Case "cbxOutputFormat"
Select Case dlgO.Control("cbxOutputFormat").Value
Case 0: strOutFormat = ".cb7"
Case 1: strOutFormat = ".cbz"
Case 2: strOutFormat = ".cbr"
End Select
Case "radWindowsTemp", "radCustomTempFolder"
blnUseTempFolder = (msgD.Control = "radWindowsTemp")
dlgO.Control("btnSelectFolder").Enabled = Not blnUseTempFolder
Case "btnSelectFolder"
Set retF = dlgO.folder("Select TEMP folder", strTmpF, True)
If retF.result = True Then
strTmpF = retF
dlgO.Control("tbxCustomTempFolder").Value = retF
End If
Case "chkDeselectAsYouProgress"
blnDeselectAfterConversion = dlgO.Control("chkDeselectAsYouProgress").Value
End Select
Loop While msgD
'If user set Cancel exit function
If dlgO.Result = 0 Then Exit Function
'Proceed otherwise
Select Case strUseSD
Case "source"
strTgtLst = CStr(ClickData.Func.sourcetab.path)
Case "destin"
strTgtLst = Cstr(ClickData.Func.desttab.path)
End Select
If blnUseTempFolder Then strTmpF = CStr(fsT.GetSpecialFolder(TemporaryFolder))
DOpus.vars.set("CBxToCBxUseWindowsTemp") = blnUseTempFolder
If Not blnUseTempFolder Then DOpus.vars.set("CBxToCBxTempFolder")= strTmpF
Set cmdDS = DOpus.Create.Command()
'cmdDS.deselect = True
'Log actions
DOpus.Output("Target folder: " & strTgtLst)
DOpus.Output("Export format: " & strOutFormat)
DOpus.Output("Resolution WH: " & lngNewWidth & "×" & lngNewHeight & " mode: " & strResizeMode)
'Loop files
For Each currentFile In clickData.func.sourcetab.selected_files
cmdDS.Clear()
cmdDS.ClearFiles()
If ((LCase(currentFile.ext) = ".cbr") Or (LCase(currentFile.ext) = ".cbz") Or (LCase(currentFile.ext) = ".cb7")) Then
DOpus.Output("Processing: " & currentFile.name_stem)
Call CBR2CB7(currentFile, strTgtLst, strOutFormat, lngNewWidth, lngNewHeight, strResizeMode, strTmpF)
If Right(currentFile.name_stem,1) = " " Then
cmdDS.RunCommand("Rename FROM """ & currentFile.name & """ TO """ & Trim(currentFile.name_stem) & currentFile.ext)
currentFile.Update
End If
If blnDeselectAfterConversion Then cmdDS.RunCommand("Select """ & currentFile.name & """ DESELECT")
Else
Set dlgO = clickData.func.Dlg
dlgO.buttons = "OK"
dlgO.message = "Comic book file extension not recognized (" + currentFile.name + ")"
dlgO.Show()
End If
Next
End Function
Function CBR2CB7(cFile, cFolder, expFmt, nWidth, nHeight, sRMode, sTempFolder)
Dim cmdR7
Dim strLastFoundFolder: Dim strDestination: Dim dirHoldsFiles
Dim itmInspectFolder
Dim fso
Dim strT: Dim strTNmStm
'Extract files to temp folder
Set cmdR7 = DOpus.Create.Command()
cmdR7.Clear()
strTNmStm = Trim(cFile.name_stem)
strDestination = sTempFolder & "\" & strTNmStm
cmdR7.RunCommand("CreateFolder """ & strDestination & """ NOSEL")
cmdR7.SetDest(strDestination)
cmdR7.AddFile(cFile)
cmdR7.AddLine("Copy CLEARREADONLY=yes EXTRACT")
cmdR7.Run()
'Find last folder that supposedly holds all the files
Set dirHoldsFiles = DOpus.FSUtil.ReadDir(strDestination,True)
strLastFoundFolder = strDestination
Do While (Not dirHoldsFiles.complete)
Set itmInspectFolder = dirHoldsFiles.Next
If itmInspectFolder.is_dir Then
strLastFoundFolder = itmInspectFolder.realpath
End If
Loop
'DOpus.Output(strLastFoundFolder)
'Resize
cmdR7.Clear()
cmdR7.ClearFiles()
cmdR7.AddFilesFromFolder(strLastFoundFolder)
Select Case sRMode
Case "Portrait"
strT = "Image HEIGHT=" & nHeight
Case "Landscape"
strT = "Image WIDTH=" & nWidth
Case "Do Not Resize"
strT = "Image "
Case Else
strT = "Image HEIGHT=" & nHeight & " WIDTH=" & nWidth
End Select
If sRMode <> "Do Not Resize" Then
cmdR7.AddLine(strT & " QUALITY=90 PRESERVEASPECTRATIO NOENLARGE REPLACE HERE")
cmdR7.Run()
End If
'Compress
cmdR7.Clear()
cmdR7.ClearFiles()
cmdR7.SetDest(cFolder)
cmdR7.AddFilesFromFolder(strLastFoundFolder)
Select Case expFmt
Case ".cb7": cmdR7.AddLine("Copy ARCHIVE=.7z CREATEFOLDER=""" & strTNmStm + ".cb7""")
Case ".cbz": cmdR7.AddLine("Copy ARCHIVE CREATEFOLDER=""" & strTNmStm + ".cbz""")
Case ".cbr": cmdR7.AddLine("Copy ARCHIVE=.rar CREATEFOLDER=""" & strTNmStm + ".cbr""")
End Select
cmdR7.Run()
'Delete temp dir
cmdR7.Clear()
cmdR7.ClearFiles()
cmdR7.AddFile(strDestination)
cmdR7.AddLine("Delete NORECYCLE QUIET FORCE ")
cmdR7.Run()
'Final cleanup
dirHoldsFiles.Close()
End Function
Function IIf(blnExpression, vTrueResult, vFalseResult)
If blnExpression Then
IIf = vTrueResult
Else
IIf = vFalseResult
End If
End Function
RESOURCES PART
<resources>
<resource name="dlgSetFileSize" type="dialog">
<dialog fontsize="8" height="250" lang="english" standard_buttons="ok,cancel" title="CBx-To-CBx Convert & Resize" width="445">
<control ellipsis="word" halign="left" height="8" name="static1" title="Set comic &book downsampling resolution" type="static" width="149" x="9" y="7" />
<control height="191" name="lstResolution" type="listbox" width="160" x="12" y="19">
<contents>
<item text="Android Tablet: 1024 × 600" />
<item text="Android Tablet: 1280 × 800" />
<item text="Android Tablet: 1920 × 1080 (Full HD)" />
<item text="Android Tablet: 2048 × 1536" />
<item text="Android Tablet: 2560 × 1440" />
<item text="Android Tablet: 2560 × 1600" />
<item text="Android Tablet: 3840 × 2160 (4k Ultra HD)" />
<item text="Android Tablet: 7680 × 4320 (8k)" />
<item text="Android Phone: 320 × 480" />
<item text="Android Phone: 480 × 800" />
<item text="Android Phone: 480 × 854" />
<item text="Android Phone: 540 × 960" />
<item text="Android Phone: 1280 × 720 (HD 720p)" />
<item text="Android Phone: 1920 × 1080 (Full HD 1080p)" />
<item text="Android Phone: 3840 × 2160 (4k Ultra HD)" />
<item text="iPhone5: 640 × 1136" />
<item text="iPhone7: 750 × 1334" />
<item text="iPhone7+: 1242 × 2208" />
<item text="iPad Mini: 1536 × 2048" />
<item text="iPad Air: 1536 × 2048" />
<item text="iPad Pro: 2048 × 2732" />
<item text="Use custom width and height" />
</contents>
</control>
<control halign="left" height="12" name="tbxNotifySelected" readonly="yes" title="Please select export resolution" type="edit" width="160" x="12" y="211" />
<control halign="left" height="8" name="static9" title="Resize orientation mode" type="static" width="84" x="183" y="16" />
<control height="10" name="chkDoNotResize" title="Do not resize, only repack" type="check" width="103" x="184" y="29" />
<control height="10" indeterminate="yes" name="chkOrientationMode" title="Orientation Mode" tristate="yes" type="check" width="100" x="184" y="41" />
<control halign="left" height="40" name="static5" title="Makes sure better size is\n preserved with aspect ratio\n kept intact (options: Auto,\n Portrait: keep height,\n Landscape: keep width)." type="static" width="100" x="198" y="54" />
<control halign="left" height="8" name="static6" title="Export comic book to:" type="static" width="79" x="325" y="16" />
<control height="10" name="radUseSource" title="Source lister" type="radio" width="55" x="331" y="28" />
<control checked="yes" height="10" name="radUseDestination" title="Destination lister" type="radio" width="74" x="331" y="40" />
<control halign="left" height="10" name="static4" title="Select custom size" type="static" width="69" x="184" y="111" />
<control halign="center" height="8" name="static2" title="Wi&dth" type="static" width="26" x="188" y="125" />
<control enable="no" halign="center" height="12" name="imgRWidth" title="1280" type="edit" width="28" x="220" y="123" />
<control halign="center" height="8" name="static3" title="Hei&ght" type="static" width="26" x="188" y="139" />
<control enable="no" halign="center" height="12" name="imgRHeight" title="800" type="edit" width="28" x="220" y="137" />
<control halign="left" height="8" name="static7" title="Output format" type="static" width="51" x="325" y="66" />
<control height="40" name="cbxOutputFormat" type="combo" width="51" x="329" y="76">
<contents>
<item text="7Z (.cb7)" />
<item text="ZIP (.cbz)" />
<item text="RAR (.cbr)" />
</contents>
</control>
<control halign="left" height="8" name="static9" title="Temporary folder" type="static" width="58" x="184" y="167" />
<control checked="yes" group="yes" height="10" name="radWindowsTemp" title="Windows TEMP folder" type="radio" width="86" x="190" y="178" />
<control height="10" name="radCustomTempFolder" type="radio" width="13" x="190" y="190" />
<control halign="left" height="12" name="tbxCustomTempFolder" readonly="yes" title="Select Your Temp Folder" type="edit" width="213" x="203" y="189" />
<control enable="no" height="14" name="btnSelectFolder" title="..." type="button" width="16" x="420" y="179" />
<control height="10" name="chkDeselectAsYouProgress" title="Progressively deselect file after conversion" type="check" width="158" x="190" y="209" />
<control halign="center" height="12" name="tbxQuality" readonly="yes" title="75" type="edit" width="21" x="399" y="122" />
<control halign="left" height="8" name="static10" title="Quality %" type="static" width="38" x="325" y="111" />
<control height="10" name="chkEnforceQuality" title="Change to max" type="check" width="65" x="330" y="123" />
<control halign="left" height="8" name="static11" title="%" type="static" width="7" x="424" y="124" />
</dialog>
</resource>
</resources>
BUGS
This program has been extensively tested against my own (large) comic book collection. Currently, all known bugs have been squashed.
CREDITS
- Directory Opus developers for the greatest software and extremely responsive help
- @Playful for providing great insight on DOpus object through his first conversion script: 'cbr to cbz', Button: cbr to cbz