Scodigo, Inc.

Log In | Register

Cart Items:
0

Trying to figure out a way to resize images before or after uploading them....???

I've got a container field in FM and I have a little script setup that lets you pull a selected photo off the camera and drop it into the container field. I then have a script that uses the SmartPill to FTP the image to our web server.

The images that come off the camera, though, are always very large. That's not a problem for me in the FM side of things, but it is for the web server. We need these images to be resized either before or after they're on the web server, doesn't really matter to me.

All of the PHP samples I've seen deal with resizing images on the local web server, which isn't really the way it would work from within a FM script using SmartPill. I tried using full paths for the file path's but I'm getting errors back no matter what I try.

Anybody done this already? I'd love to get some tips. Any info would be greatly appreciated. Thanks!

Here's what I use to scale

Here's what I use to scale images. Without any hard details about the problem its impossible to tell where you're having the problem but I hope this helps.

$img = ImageCreateFromJPEG($srcpath);
CreateImage($img, $destpath, $size);

function CreateImage($img, $path ,$size)
{
$old_x = imageSX($img);
$old_y = imageSY($img);

if ($old_x > $old_y)
{
$thumb_w = $size;
$thumb_h = $old_y * ($size/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w = $old_x * ($size/$old_y);
$thumb_h = $size;
}
if ($old_x == $old_y)
{
$thumb_w = $size;
$thumb_h = $size;
}

$dstimg = ImageCreateTrueColor($thumb_w, $thumb_h);
ImageCopyResampled($dstimg, $img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
ImageJPEG($dstimg, $path);
ImageDestroy($dstimg);
}

ok

I actually do have this working now, but I wound up going a pretty crazy route that involves using the SmartPill to basically call a small PHP web service that handles resizing the images and moving them to their final location.

My trouble is that I don't seem to be able to make it work using disk drive file paths locally inside the SmartPill itself. For example, my scripts are setup to export the container field contents and then FTP it off the drive. But then when I try and use that same file path that the FTP part uses to resize the image before hand I get errors back about not finding the image to open it.

Maybe I was just doing something stupid. Are you doing this inside the SmartPill plugin directly?

File path

Micah Woods's picture

Here's a snippet of code used to rotate an image. It uses the temp path as returned by FileMaker as the working directory. I'm not sure why the file path would work for FTP but not for scaling? Also, wouldn't you want to scale first, then FTP?

Code for rotating an image (the images is exported by FileMaker first).

"
$filename = '" &

If (
Abs ( Get ( SystemPlatform ) ) = 1 ;
Right ( Get ( TemporaryPath ) ; Length ( Get ( TemporaryPath ) ) - Position ( Get ( TemporaryPath ) ; "/" ; 1 ; 2 ) + 1 ) ;
// Else
Right ( Get ( TemporaryPath ) ; Length ( Get ( TemporaryPath ) ) - 1 )
) &

$tempFileName &

"';¶
$degrees = -90;¶

// Load image¶
$image = imagecreatefrom" & $fileType & "($filename);¶

// Rotate image¶
$rotate = imagerotate($image, $degrees, 0);¶

// Output image¶
image" & $fileType & "($rotate, $filename);
"

Regards,
Micah