Hello everybody,
i am looking for a "simple" script to resize images for our ActiveDirectory. The feature is, that the imported picture should be resized to a bytesize of 100 KB and scale automatically. Width and higth is not possible and can have a higher resolution.
Does a script exist or someone know how to realize?
Greez
Automatically resize of images
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Automatically resize of images
$image = [system.drawing.Bitmap]::FromFile(<filepath>)
See attached script.
See attached script.
- Attachments
-
- Set-ImageSize.ps1
- (4.58 KiB) Downloaded 158 times
Re: Automatically resize of images
Thank you very much for the fast answer.
What I can say is that this script looks very nice and i can find a use in it. But i have one more question: Can i set a fixedlength of 100 KB and let the script scale the image automatically to the right size of 100 KB? If yes, how i need to modify the script?
What I can say is that this script looks very nice and i can find a use in it. But i have one more question: Can i set a fixedlength of 100 KB and let the script scale the image automatically to the right size of 100 KB? If yes, how i need to modify the script?
Re: Automatically resize of images
Sorry but that is not how images work. An image requires a specific number of bytes. A JPEG image requires as many bytes ass there are cells times the color depth. A JPEG can be compressed but, as with all compression, the size of the result is entirely dependent on the content of the source. It cannot be predicted or requested.
A 300Mb JPEG uncompressed can be reduced by anywhere from 2 to more than 10 times using 80% compression. Any raw JOEG can be reduced by at least 30% in most cases using lossless compression.
You could compress in a loop by incremental amounts until you reach a desired size or just compress by 80% an hoe it is enough.
Resizing a JPEG does not reduce the size of the file.
Search for command line utilities designed to reduce image files. These are common for web development for compressing images for web display. YOu can also use the code posted to access the JEG as an image file (bitmap) and use the codecs to compress the image.
A 300Mb JPEG uncompressed can be reduced by anywhere from 2 to more than 10 times using 80% compression. Any raw JOEG can be reduced by at least 30% in most cases using lossless compression.
You could compress in a loop by incremental amounts until you reach a desired size or just compress by 80% an hoe it is enough.
Resizing a JPEG does not reduce the size of the file.
Search for command line utilities designed to reduce image files. These are common for web development for compressing images for web display. YOu can also use the code posted to access the JEG as an image file (bitmap) and use the codecs to compress the image.