Skip to content

Instantly share code, notes, and snippets.

@UskeS
Created November 8, 2023 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UskeS/dd4a7c73332674a8d61ee0abab98fce5 to your computer and use it in GitHub Desktop.
Save UskeS/dd4a7c73332674a8d61ee0abab98fce5 to your computer and use it in GitHub Desktop.
[InDesign] 画像のトリミングが閾値以上かどうか調べる
/**
* @fileoverview checkTrimedImageSize:画像のトリミングが閾値以上かどうか調べるスクリプト
* @author Uske_S
* @version v1.0.0
* @description
* 閾値の変更は threshold変数 の値を変更(デフォルトは15pt = 約5.3mm)
* 動作確認は macOS 11.7.8(Big Sur)/InDesign 2022(v17.4.2)
* 本スクリプトによるいかなる不都合も作者は保障できかねますので,自己責任においてお使いください
*/
var threshold = 15; //閾値(pt)
app.scriptPreferences.measurementUnit = MeasurementUnits.points;
var doc = app.activeDocument;
var images = doc.allGraphics;
var targets = [];
app.doScript(main, ScriptLanguage.JAVASCRIPT, null, UndoModes.ENTIRE_SCRIPT);
function main() {
for (var i = 0, len = images.length; i < len; i++) {
var rotationAngle = images[i].parent.rotationAngle; // 配置されているフレームの回転角度
images[i].parent.rotationAngle = 0; // 計測のため一度回転を消す
var parentFrameBounds = images[i].parent.geometricBounds; // 配置されているフレーム座標
var placedImageBounds = images[i].geometricBounds; // 配置されている画像の座標
var boundsDiff = [
round3digits(placedImageBounds[0]) - round3digits(parentFrameBounds[0]),
round3digits(placedImageBounds[1]) - round3digits(parentFrameBounds[1]),
-(round3digits(placedImageBounds[2]) - round3digits(parentFrameBounds[2])),
-(round3digits(placedImageBounds[3]) - round3digits(parentFrameBounds[3])),
];
images[i].parent.rotationAngle = rotationAngle; // 回転角度を戻す
if (boundsDiff[0] >= -threshold && boundsDiff[1] >= -threshold && boundsDiff[2] >= -threshold && boundsDiff[3] >= -threshold) {
continue;
}
targets.push(images[i]);
}
for (var i = 0; i < targets.length; i++) {
targets[i].select();
app.activeWindow.zoomPercentage = 150;
if (confirm("スクリプトを中断しますか?", false)) {
exit();
}
}
alert("終了しました");
}
// 小数点以下3桁で四捨五入して値を返す(桁数を変えるには digits を変える)
function round3digits(val) {
var digits = 3;
return Math.round(val * Math.pow(10, digits)) / Math.pow(10, digits);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment