to kill a process named mplayer
ps -ef|grep [m]player|awk '{print $2}'|xargs kill
Tuesday, February 26, 2008
Thursday, February 21, 2008
ImageMagick Scritps to Crop Borders
I was experimenting ImageMagic's capability to crop images to come up an automated way for PWP's scanning issue. Made some progress, yet far from the solution.
convert SS0124570.tif -gravity northwest -crop 55%x55%+110+90 -quiet +repage tt.tif
convert SS0124570.tif -gravity northwest -crop 55%x55%+110+90 -quiet +repage tt.tif
Use ImageMagick to Scale Images
'This script produces resized images out of a given
'directory on the fly by using imagemagick
'This script is compiled by John Zhou, MWH Global, 1/14/2007
'This script is not part of any deliverables of PWP eGIS program currently undertaken by MWH
'This script is given to help PWP resizing large scanned images for free.
'Neither John Zhou, personally or MWH as a company is responsible for any damage caused by using this script.
'PWP should use this script at their own risk and discreetion.
'depending the amount file to be proceessed, it may take minutes to hours to run the script. Be patient.
'Need ImageMagick installed to run the script http://www.imagemagick.org/script/binary-releases.php#windows
Option Explicit 'This is to ensure no variable is used without defintion.
On Error Resume Next
Dim img 'ImageMagick object
Dim inputdir 'original directory
Dim inputfld ' file collection in the original folder
Dim outputdir 'destination directory
Dim outputfld 'file collection in the destination folder
Dim fso 'filesystem object
Dim f 'file object
Dim tnSize 'scale size
Dim nFileSize 'largest file size to be resized
inputdir = "d:\water\" 'This is the directory where the original files/images located
outputdir = "d:\water\"'This is the directory where the resized images will be located
'define how big the thumbnail should be
tnSize = "50%" 'default to reduce 1/4 size of original, it can be changed
nFileSize = 100000000 ' default only file larger than 100 Mega need to be resized
Set img = CreateObject("ImageMagickObject.MagickImage.1") 'Create a ImageMagick Object
Set fso = CreateObject("Scripting.FileSystemObject") 'Create a File System Object
Set inputfld = fso.GetFolder(inputdir).Files 'Get all files in the original folder
Set outputfld = fso.GetFolder(outputdir).Files 'Get all files in the destination folder
'reads all files in input dir, resizes them and copies them into output dir
'OPTIONS FOR CONVERT FUNCTION (taken from http://imagemagick.org/script/command-line-options.php):
'
'-resize width{%}{@} {!} {<} {>}
'resize an image.
'By default, the width and height are maximum values. That is, the image is expanded or contracted to fit the width and height value while maintaining the aspect ratio of the image. Append an exclamation point to the geometry to force the image size to exactly the size you specify. For example, if you specify 640x480! the image width is set to 640 pixels and height to 480.
'If only the width is specified, the width assumes the value and the height is chosen to maintain the aspect ratio of the image. Similarly, if only the height is specified (e.g., -resize x256, the width is chosen to maintain the aspect ratio.
'To specify a percentage width or height instead, append %. The image size is multiplied by the width and height percentages to obtain the final image dimensions. To increase the size of an image, use a value greater than 100 (e.g. 125%). To decrease an image's size, use a percentage less than 100.
'Use @ to specify the maximum area in pixels of an image.
'Use <> resizes the image only if both of its dimensions are less than the geometry specification. For example, if you specify 640x480 and the image size is 256x256, the image size does not change. However, if the image is 512x512 or 1024x1024, it is resized to 480x480. Enclose the geometry specification in quotation marks to prevent the <> from being interpreted by your shell as a file redirection.
'if the -filter option precedes the -resize option, the image is resized with the specified filter.
'If the -support option precedes the -resize option, the image is resized with the specified support.
For Each f In inputfld 'for each file in the original file folder
'if and only if there is no "resized" image in the destination folder (avoid redudant work) and the original file size is larger than nFileSize
If Not fso.fileexists(outputdir & fso.GetBaseName(f) & "_resize." & fso.GetExtensionName(f)) and f.Size > nFileSize Then
' Use ImageMagick's Convert function to resize and add "_resize" at the end of original file name
rs = img.Convert("-quiet","-resize",tnSize,inputdir & f.Name,outputdir & fso.GetBaseName(f) & "_resize." & fso.GetExtensionName(f))
End If
Next
WScript.Echo "Done" 'tell the user the file is done
Set img=Nothing
'directory on the fly by using imagemagick
'This script is compiled by John Zhou, MWH Global, 1/14/2007
'This script is not part of any deliverables of PWP eGIS program currently undertaken by MWH
'This script is given to help PWP resizing large scanned images for free.
'Neither John Zhou, personally or MWH as a company is responsible for any damage caused by using this script.
'PWP should use this script at their own risk and discreetion.
'depending the amount file to be proceessed, it may take minutes to hours to run the script. Be patient.
'Need ImageMagick installed to run the script http://www.imagemagick.org/script/binary-releases.php#windows
Option Explicit 'This is to ensure no variable is used without defintion.
On Error Resume Next
Dim img 'ImageMagick object
Dim inputdir 'original directory
Dim inputfld ' file collection in the original folder
Dim outputdir 'destination directory
Dim outputfld 'file collection in the destination folder
Dim fso 'filesystem object
Dim f 'file object
Dim tnSize 'scale size
Dim nFileSize 'largest file size to be resized
inputdir = "d:\water\" 'This is the directory where the original files/images located
outputdir = "d:\water\"'This is the directory where the resized images will be located
'define how big the thumbnail should be
tnSize = "50%" 'default to reduce 1/4 size of original, it can be changed
nFileSize = 100000000 ' default only file larger than 100 Mega need to be resized
Set img = CreateObject("ImageMagickObject.MagickImage.1") 'Create a ImageMagick Object
Set fso = CreateObject("Scripting.FileSystemObject") 'Create a File System Object
Set inputfld = fso.GetFolder(inputdir).Files 'Get all files in the original folder
Set outputfld = fso.GetFolder(outputdir).Files 'Get all files in the destination folder
'reads all files in input dir, resizes them and copies them into output dir
'OPTIONS FOR CONVERT FUNCTION (taken from http://imagemagick.org/script/command-line-options.php):
'
'-resize width{%}{@} {!} {<} {>}
'resize an image.
'By default, the width and height are maximum values. That is, the image is expanded or contracted to fit the width and height value while maintaining the aspect ratio of the image. Append an exclamation point to the geometry to force the image size to exactly the size you specify. For example, if you specify 640x480! the image width is set to 640 pixels and height to 480.
'If only the width is specified, the width assumes the value and the height is chosen to maintain the aspect ratio of the image. Similarly, if only the height is specified (e.g., -resize x256, the width is chosen to maintain the aspect ratio.
'To specify a percentage width or height instead, append %. The image size is multiplied by the width and height percentages to obtain the final image dimensions. To increase the size of an image, use a value greater than 100 (e.g. 125%). To decrease an image's size, use a percentage less than 100.
'Use @ to specify the maximum area in pixels of an image.
'Use <> resizes the image only if both of its dimensions are less than the geometry specification. For example, if you specify 640x480 and the image size is 256x256, the image size does not change. However, if the image is 512x512 or 1024x1024, it is resized to 480x480. Enclose the geometry specification in quotation marks to prevent the <> from being interpreted by your shell as a file redirection.
'if the -filter option precedes the -resize option, the image is resized with the specified filter.
'If the -support option precedes the -resize option, the image is resized with the specified support.
For Each f In inputfld 'for each file in the original file folder
'if and only if there is no "resized" image in the destination folder (avoid redudant work) and the original file size is larger than nFileSize
If Not fso.fileexists(outputdir & fso.GetBaseName(f) & "_resize." & fso.GetExtensionName(f)) and f.Size > nFileSize Then
' Use ImageMagick's Convert function to resize and add "_resize" at the end of original file name
rs = img.Convert("-quiet","-resize",tnSize,inputdir & f.Name,outputdir & fso.GetBaseName(f) & "_resize." & fso.GetExtensionName(f))
End If
Next
WScript.Echo "Done" 'tell the user the file is done
Set img=Nothing
Monday, February 18, 2008
Reverse Selection Set
I created this short script to switch selectionset for all layers in one map. It may have no generic value, but it does demonstrate the selectionset interface.
Sub SwitchSelection()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As ILayer
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.ActiveView
Dim pFLayer As IFeatureLayer
Dim pEnumLayer As IEnumLayer
Set pEnumLayer = pMap.Layers
Set pLayer = pEnumLayer.Next
Do While Not pLayer Is Nothing
If TypeOf pLayer Is IFeatureLayer Then
Set pFLayer = pLayer
Dim pFSel As IFeatureSelection
Set pFSel = pFLayer
Dim pSelFeats As ISelectionSet
Set pSelFeats = pFSel.SelectionSet
Dim pAllFeats As ISelectionSet
Set pAllFeats = pFLayer.FeatureClass.Select(Nothing, esriSelectionTypeIDSet, esriSelectionOptionNormal, Nothing)
Dim pNewSel As ISelectionSet
pAllFeats.Combine pSelFeats, esriSetDifference, pNewSel
Set pFSel.SelectionSet = pNewSel
End If
Set pLayer = pEnumLayer.Next
Loop
pMxDoc.ActiveView.Refresh
Sub SwitchSelection()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As ILayer
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.ActiveView
Dim pFLayer As IFeatureLayer
Dim pEnumLayer As IEnumLayer
Set pEnumLayer = pMap.Layers
Set pLayer = pEnumLayer.Next
Do While Not pLayer Is Nothing
If TypeOf pLayer Is IFeatureLayer Then
Set pFLayer = pLayer
Dim pFSel As IFeatureSelection
Set pFSel = pFLayer
Dim pSelFeats As ISelectionSet
Set pSelFeats = pFSel.SelectionSet
Dim pAllFeats As ISelectionSet
Set pAllFeats = pFLayer.FeatureClass.Select(Nothing, esriSelectionTypeIDSet, esriSelectionOptionNormal, Nothing)
Dim pNewSel As ISelectionSet
pAllFeats.Combine pSelFeats, esriSetDifference, pNewSel
Set pFSel.SelectionSet = pNewSel
End If
Set pLayer = pEnumLayer.Next
Loop
pMxDoc.ActiveView.Refresh
Setting Definition Queries for all layers
I just need to set definition query for all layers in one map. This script is just to demonstrate how to navigate layers in one map and the IFeatureLayerDefinition interface. I actually can write the "dropdown" box for PWP's feederID.
Sub SetDQ()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As ILayer
Set pMxDoc = ThisDocumentSet
pMap = pMxDoc.ActiveView
Dim pFLayerDef As IFeatureLayerDefinition
Dim pEnumLayer As IEnumLayer
Set pEnumLayer = pMap.Layers
Set pLayer = pEnumLayer.Next
Do While Not pLayer Is Nothing
If TypeOf pLayer Is IFeatureLayer Then
Set pFLayerDef = pLayer
pFLayerDef.DefinitionExpression = "DELIVERY ='5'"
End If
Set pLayer = pEnumLayer.Next
Loop
pMxDoc.ActivatedView.Refresh
End Sub
Sub SetDQ()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As ILayer
Set pMxDoc = ThisDocumentSet
pMap = pMxDoc.ActiveView
Dim pFLayerDef As IFeatureLayerDefinition
Dim pEnumLayer As IEnumLayer
Set pEnumLayer = pMap.Layers
Set pLayer = pEnumLayer.Next
Do While Not pLayer Is Nothing
If TypeOf pLayer Is IFeatureLayer Then
Set pFLayerDef = pLayer
pFLayerDef.DefinitionExpression = "DELIVERY ='5'"
End If
Set pLayer = pEnumLayer.Next
Loop
pMxDoc.ActivatedView.Refresh
End Sub
Subscribe to:
Posts (Atom)