0 votes

Hi,
I would like to launch a script to optimize photo to 96x96 when photo is updated.
I use a command line to do the job but i can figure out how to get the photo before the user update. Any chance Adaxes stores the photo in a temp folder before it loads it to AD ?

Thanks

Stephen

by (800 points)

1 Answer

0 votes
by (18.0k points)
selected by
Best answer

Hi Stephen,

Adaxes doesn't store photos in temporary files. However, you can do it by yourself with the help of a PowerShell script.
The following script saves the photo to a temporary file, executes an external command for this file, and then replaces the user-specified photo with the modified one.

if (-not $Context.IsPropertyModified("thumbnailPhoto"))
{
    return; # the thumbnailPhoto property is not modified
}
# Get the thumbnailPhoto
$thumbnailPhotoBytes = $Context.GetModifiedPropertyValue("thumbnailPhoto");
if ($thumbnailPhotoBytes -eq $NULL)
{
     return; # the thumbnailPhoto property is being deleted
}

# Write the photo to temporary file
$tmpFilePath = [System.IO.Path]::GetTempFileName();
[System.IO.File]::WriteAllBytes($tmpFilePath, $thumbnailPhotoBytes);

# TODO: Launch an external command to resize the photo ($tmpFilePath)

# Read the modified file
$thumbnailPhotoBytes = [System.IO.File]::ReadAllBytes($tmpFilePath);
# Delete the temporary file
[System.IO.File]::Delete($tmpFilePath);

# Replace the photo with the modified one
$Context.SetModifiedPropertyValue("thumbnailPhoto", $thumbnailPhotoBytes);
0

You're a genius :-)

Thanks a lot !

0

Glad to help :)

0

This is exactly what I've been looking for...I'm using ImageMagik via command line now to shrink/crop/resize our user images for AD. When I add the command line option in the field, I receive an error when attempting to do the above. I think my problem is the fact that the images we have are 1MB + in size. When we use the command line it shrinks all the files properly etc. But i can't seem to figure out how to get it to work with this script.

if (-not $Context.IsPropertyModified("thumbnailPhoto"))
{
    return; # the thumbnailPhoto property is not modified
}
# Get the thumbnailPhoto
$thumbnailPhotoBytes = $Context.GetModifiedPropertyValue("thumbnailPhoto");
if ($thumbnailPhotoBytes -eq $NULL)
{
     return; # the thumbnailPhoto property is being deleted
}

# Write the photo to temporary file
$tmpFilePath = [System.IO.Path]::GetTempFileName();
[System.IO.File]::WriteAllBytes($tmpFilePath, $thumbnailPhotoBytes);

# TODO: Launch an external command to resize the photo ($tmpFilePath)
"C:\Adaxes\Scripts\Convert\Convert.exe -quality 96 -depth 8 -strip -thumbnail 96x96^ -gravity Center -crop 96x96+0+0 $tmpFilePath\$thumbnailPhotoBytes $tmpFilePath\Converted.jpg"
# Read the modified file
$thumbnailPhotoBytes = [System.IO.File]::ReadAllBytes($tmpFilePath);
# Delete the temporary file
[System.IO.File]::Delete($tmpFilePath);

# Replace the photo with the modified one
$Context.SetModifiedPropertyValue("thumbnailPhoto", $thumbnailPhotoBytes);

0

It would be awesome if the pics got resized automatically when imported from the web portal! :)

0

Hello,

As to the script, we've assigned the task to our script guy. We'll update this topic as soon as he comes up with something.

As to resizing pictures on import, we already have this feature in our TODO list. We'll consider it for one of the future releases.

0

Hello,

Here's the modified script that should do the job.

if (-not $Context.IsPropertyModified("thumbnailPhoto"))
{
    return; # the thumbnailPhoto property is not modified
}
# Get the thumbnailPhoto
$thumbnailPhotoBytes = $Context.GetModifiedPropertyValue("thumbnailPhoto");
if ($thumbnailPhotoBytes -eq $NULL)
{
     return; # the thumbnailPhoto property is being deleted
}

# Write the photo to temporary file
$tmpFilePath = [System.IO.Path]::GetTempFileName();
[System.IO.File]::WriteAllBytes($tmpFilePath, $thumbnailPhotoBytes);

# TODO: Launch an external command to resize the photo ($tmpFilePath)
& "C:\Adaxes\Scripts\Convert\Convert.exe" "$tmpFilePath" -quality 96 -depth 8 -strip -thumbnail 96x96^ -gravity Center -crop 96x96+0+0 "$tmpFilePath" 

# Read the modified file
$thumbnailPhotoBytes = [System.IO.File]::ReadAllBytes($tmpFilePath);
# Delete the temporary file
[System.IO.File]::Delete($tmpFilePath);

# Replace the photo with the modified one
$Context.SetModifiedPropertyValue("thumbnailPhoto", $thumbnailPhotoBytes);

The thing is that whenever you launch an executable file in PowerShell, it should be preseed with an & symbol. Otherwise PowerShell will treat the line as a PowerShell command.

Also, you saved the converted file to $tmpFilePath\Converted.jpg, but tried to upload to directory not the converted file, but the original source file before conversion.

Related questions

0 votes
1 answer

This is the query I am using (basically if "Photo" is empty): (&(sAMAccountType=805306368)(!(photo=*))) which returns everyone in AD, not just users without photos. ... sAMAccountType=805306368)(!(manager=*))) What am I doing wrong? Can my query be fixed?

asked Jun 11, 2012 by MarkManley (90 points)
0 votes
1 answer

Let's say I have a Business Rule that is fired prior to adding members to a group. Is it possible to get the number of objects being added to that group as ... that tells me that 6 objects will be added or is each added user treated completely independently?

asked Apr 20 by ngb (90 points)
0 votes
1 answer

Hi Adaxes Team I have created a business rule which sends a mail to our helpdesk staff after a user sets a new pw with the self password reset function. The user should ... . If this is not possible yet, please forward it as a suggestion :) regards pudong

asked Feb 4 by pudong (580 points)
0 votes
1 answer

Every time when I try to save a change for a business rule in Adaxes Console, I got the error "An error occurred while saving the custom command. Requested Service not found" I close and open the console again but doesn't help.

asked Aug 9, 2021 by kfung00 (20 points)
0 votes
1 answer

I am trying to create a business rule to send an email to the manager of the group when a member is added or removed from a rule-based group. I have created the business rule and it works for other groups but not for a rule-based group. Can this be done?

asked Jul 19, 2021 by mark.it.admin (2.1k points)
2,803 questions
2,535 answers
6,605 comments
62,365 users