mcp-duojie-image 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/provider.js +28 -3
  2. package/package.json +1 -1
package/dist/provider.js CHANGED
@@ -46,18 +46,43 @@ function mapSize(size) {
46
46
  function isOpenAIImageModel(model) {
47
47
  return model === "gpt-image-2";
48
48
  }
49
+ function parseAspectRatio(aspectRatio) {
50
+ const match = aspectRatio?.match(/^(\d+):(\d+)$/);
51
+ if (!match)
52
+ return [1, 1];
53
+ return [Number(match[1]), Number(match[2])];
54
+ }
55
+ function mapOpenAI4KSize(aspectRatio) {
56
+ const [ratioWidth, ratioHeight] = parseAspectRatio(aspectRatio);
57
+ const maxPixels = 3840 * 2160;
58
+ const maxEdge = 3840;
59
+ let width = Math.floor(Math.sqrt((maxPixels * ratioWidth) / ratioHeight));
60
+ let height = Math.floor((width * ratioHeight) / ratioWidth);
61
+ if (width > maxEdge) {
62
+ width = maxEdge;
63
+ height = Math.floor((width * ratioHeight) / ratioWidth);
64
+ }
65
+ if (height > maxEdge) {
66
+ height = maxEdge;
67
+ width = Math.floor((height * ratioWidth) / ratioHeight);
68
+ }
69
+ width = Math.floor(width / 8) * 8;
70
+ height = Math.floor(height / 8) * 8;
71
+ return `${width}x${height}`;
72
+ }
49
73
  function mapOpenAISize(size, aspectRatio) {
50
74
  const squareBySize = {
51
75
  "512px": "512x512",
52
76
  "1K": "1024x1024",
53
77
  "2K": "2048x2048",
54
- "4K": "4096x4096",
55
78
  };
79
+ if (size === "4K")
80
+ return mapOpenAI4KSize(aspectRatio);
56
81
  if (aspectRatio === "16:9" || aspectRatio === "3:2" || aspectRatio === "4:3") {
57
- return size === "2K" ? "2048x1536" : size === "4K" ? "4096x3072" : "1536x1024";
82
+ return size === "2K" ? "2048x1536" : "1536x1024";
58
83
  }
59
84
  if (aspectRatio === "9:16" || aspectRatio === "2:3" || aspectRatio === "3:4") {
60
- return size === "2K" ? "1536x2048" : size === "4K" ? "3072x4096" : "1024x1536";
85
+ return size === "2K" ? "1536x2048" : "1024x1536";
61
86
  }
62
87
  return squareBySize[size] ?? "1024x1024";
63
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-duojie-image",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "MCP server for image generation via duojie.games",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",