Paul
unread,Oct 6, 2011, 6:41:39 PM10/6/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ResourceSpace
Hi everyone,
At my company, we are using StaticSync and leaving our source images
in their original location. The only images that are created for
ResourceSpace are for preview/thumbnail purposes. So, we were finding
ImageMagick/ufraw pretty slow at converting CR2 files (20-30secs a
file). Then I learned the Canon 5D Mark II embeds a full res JPG in
the CR2 (I think many other cameras do this as well... although maybe
not full res jpegs). Extracting this embedded jpg with ufraw-batch is
super-fast. The embedded jpg might not be the highest quality, but it
looks pretty nice and works for our purposes. So I wrote some quick
code to skip the RAW conversion if an embedded jpg of sufficient
resolution is found.
This code probably doesn't take every case into consideration. I am
not familiar enough with ResourceSpace as a whole yet. BUT, I am
sharing as a reference for anyone who finds themselves in a similar
situation:
image_processing.php -- in function create_previews_using_im()
..
..
$hpr_path=get_resource_path($ref,true,"hpr",false,"jpg",-1,1,false,"",
$alternative);
if (file_exists($hpr_path) && !$previewbased) {unlink($hpr_path);}
$lpr_path=get_resource_path($ref,true,"lpr",false,"jpg",-1,1,false,"",
$alternative);
if (file_exists($lpr_path) && !$previewbased) {unlink($lpr_path);}
$scr_path=get_resource_path($ref,true,"scr",false,"jpg",-1,1,false,"",
$alternative);
if (file_exists($scr_path) && !$previewbased) {unlink($scr_path);}
$scr_wm_path=get_resource_path($ref,true,"scr",false,"jpg",-1,1,true,"",
$alternative);
if (file_exists($scr_wm_path) && !$previewbased)
{unlink($scr_wm_path);}
$emb_jpg_path=get_resource_path($ref,true,"emb",false,"jpg",-1,1,false,"",
$alternative);
if (file_exists($emb_jpg_path)) {unlink($emb_jpg_path);}
$prefix = '';
# Camera RAW images need prefix
if (preg_match('/^(dng|nef|x3f|cr2|crw|mrw|orf|raf|dcr)$/i',
$extension, $rawext)) { $prefix = $rawext[0] .':'; }
# Locate imagemagick.
$identcommand=$imagemagick_path . "/bin/identify";
if (!file_exists($identcommand)) {$identcommand=$imagemagick_path .
"/identify";}
if (!file_exists($identcommand)) {$identcommand=$imagemagick_path .
"\identify.exe";}
if (!file_exists($identcommand)) {exit("Could not find ImageMagick
'identify' utility.'");}
$orig_identcommand=$identcommand;
$sizes="";
if ($thumbonly) {$sizes=" where id='thm' or id='col'";}
if ($previewonly) {$sizes=" where id='thm' or id='col' or id='pre'
or id='scr'";}
$ps=sql_query("select * from preview_size $sizes order by width
desc, height desc");
#################################################################################################################################
# FOR SPEED PURPOSES
# if RAW format, attempt to pull embedded jpg out.
# if the embedded jpg is large enough to generate all our preview
formats go with it. This forgoes the timely process of
# converting the actual RAW data.
##################################################################################################################################
$sw=-1;$sh=-1;
$using_emb_jpg = false;
if(count($ps)>0 && in_array($extension, array("cr2", "crw", "dng",
"nef")))
{
$emb_jpg_command = "/usr/bin/ufraw-batch --
output=".escapeshellarg($emb_jpg_path)." --embedded-image
".escapeshellarg($file);
$emb_jpg_output=shell_exec($emb_jpg_command);
if(file_exists($emb_jpg_path))
{
# Get image's dimensions.
$identcommand = $orig_identcommand . ' -format %wx%h '.
escapeshellarg($emb_jpg_path) .'[0]';
$identoutput=shell_exec($identcommand);
preg_match('/^([0-9]+)x([0-9]+)$/ims',$identoutput,$smatches);
if ((@list(,$emd_jpg_sw,$emd_jpg_sh) = $smatches)===false)
{ return false; }
if($emd_jpg_sw>=$ps[0]["width"] && $emd_jpg_sh>=$ps[0]["height"])
{
$using_emb_jpg = true;
$file = $emb_jpg_path;
$extension = "jpg";
$sw = $emd_jpg_sw;
$sh = $emd_jpg_sh;
}
}
}
# If an embedded jpeg wasn't found in a RAW format or the orig
source is not RAW, determine orig source's dimensions
# Get image's dimensions.
if(!$using_emb_jpg)
{
$identcommand = $orig_identcommand . ' -format %wx%h '.
escapeshellarg($prefix . $file) .'[0]';
$identoutput=shell_exec($identcommand);
preg_match('/^([0-9]+)x([0-9]+)$/ims',$identoutput,$smatches);
if ((@list(,$sw,$sh) = $smatches)===false) { return false; }
}
for ($n=0;$n<count($ps);$n++)
{
..
..
..
# if we extracted an embedded jpg from a RAW file, delete it now.
if (file_exists($emb_jpg_path)) {unlink($emb_jpg_path);}
return true;