AppleScript调整图像大小并以新名称保存

时间:2014-05-18 19:59:03

标签: applescript filemaker

我在FilemakerPro中调用了一个Applescript。 这些是我试图实现的目标:

  • 图像存储在容器字段中。
  • 它将名称和路径存储在不同的字段中。

正在激活Applescript以执行这些操作:

  • 从FilemakerPro
  • 检索数据
  • 检查是否存在与字段“calculate_merk_id”
  • 同名的文件夹
  • 如果没有,则会创建文件夹
  • 它会创建一个新的图像文件,该名称在调整为155 x 134后应将“__small”添加到其名称中,并将其存储在此文件夹中
  • 它创建了一个新的图像文件,在将其大小调整为400 x 400后,该名称应在其名称中添加“__large”,并将其存储在此文件夹中

我收到的第一个错误是它无法检索图像的尺寸。此外,它不会创建我调整大小的图像......任何想要帮助我的人都在正确的方向吗?

set pad to cell "ServerImagePath" of current record
set filenaam to cell "afbeelding_local_vol_pad" of current record
set foldernaam to cell "calculate_merk_id" of current record
set volle_foldernaam to cell "ServerImageFolder" of current record
set volle_filenaam to cell "ServerImageFile" of current record

set target_small_width to 155
set target_small_height to 134
set target_large_width to 400
set target_large_height to 400

tell application "Finder"
if not exists volle_foldernaam then
          make new folder at pad with properties {name: foldernaam}
   end if

   duplicate filenaam to volle_foldernaam with replacing

   tell application "Image Events"
      launch
      set this_image to filenaam
      copy dimensions of this_image to {W, H}

      if target_small_width is greater than target_small_height then

         if W is greater than H then

            set the scale_length to (W * target_small_height) / H
            set the scale_length to round scale_length rounding as taught in school
         else

             set the scale_length to target_small_height
          end if

       else if target_small_height is greater than target_small_width then

          if H is greater than W then

             set the scale_length to (H * target_small_with) / W
             set the scale length to round scale_length rounding as taught in school
          else

            set the scale_length to target_small_width
          end if

       else 
           set the scale_length to target_small_height
       end if

       scale this_image to size scale_length

       pad this_image to dimensions {target_small_width, target_small_height}


       save this_image as this_name & "__small"

       close this_image

   end tell

end tell

2 个答案:

答案 0 :(得分:0)

您忘了打开图片

set this_image to filenaam

应该是

set this_image to open filenaam

答案 1 :(得分:0)

为什么不在FileMaker中本地执行此操作? FM 12及更高版本具有GetThumbnail()函数。脚本可以将重新调整大小的图像计算为全局字段,然后从全局字段中导出图像。完全跨平台将适用于OSX和Windows,甚至是FileMaker Go。

Set Field [ photo_temp_g ; GetThumbnail ( photo_original ; width ; height ) ]
Commit Record/Request []
Export Field Contents [ photo_temp_g ; “<filename>” ]