PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
← All changes | app/Draft/Controllers/ImageController.php +23 -4 3.1.5 → 3.2.2 View file →
@@ -23,8 +23,16 @@
23 23
24 24 class ImageController
25 25 {
26 26 /**
27 + * Must match `PILL_RIGHT_EDGE` in `src/Shared/lib/ai-label.js`.
28 + *
29 + * @var float
30 + */
31 + // phpcs:ignore PSR12.Properties.ConstantVisibility.NotFound -- 7.0 floor: no const visibility
32 + const PILL_RIGHT_EDGE = 0.85;
33 +
34 + /**
27 35 * Upload the provided image
28 36 *
29 37 * @param \WP_REST_Request $request - The request.
30 38 * @return \WP_REST_Response
@@ -36,9 +44,20 @@
36 44 require_once ABSPATH . 'wp-admin/includes/file.php';
37 45 require_once ABSPATH . 'wp-admin/includes/image.php';
38 46 }
39 47
48 + // media_sideload_image() takes no file name; it names the file from the URL.
49 + $markAiFilename = function ($file) {
50 + $info = pathinfo($file['name']);
51 + $file['name'] = "{$info['filename']}-ai-generated.{$info['extension']}";
52 + return $file;
53 + };
54 + if ($request->get_param('ai_generated')) {
55 + add_filter('wp_handle_sideload_prefilter', $markAiFilename);
56 + }
57 +
40 58 $imageId = \media_sideload_image($request->get_param('source'), 0, null, 'id');
59 + remove_filter('wp_handle_sideload_prefilter', $markAiFilename);
41 60
42 61 // Without this the caller can't tell a failed upload from a declined one.
43 62 if (\is_wp_error($imageId)) {
44 63 return new \WP_REST_Response(['message' => $imageId->get_error_message()], 500);
@@ -84,10 +103,10 @@
84 103 );
85 104 }
86 105
87 106 /**
88 - * Composite the client-rendered disclosure label onto the attachment,
89 - * bottom-right at a 16px inset, matching the canvas-path stamp.
107 + * Composite the client-rendered disclosure label onto the attachment. The
108 + * PNG already includes its border, unlike the canvas path's fill box.
90 109 *
91 110 * @param int $imageId - The attachment ID.
92 111 * @param string $labelPath - Path to the uploaded label PNG.
93 112 * @return void
@@ -122,10 +141,10 @@
122 141 imagealphablending($image, true);
123 142 imagecopyresampled(
124 143 $image,
125 144 $label,
126 - ($width - $labelWidth - 16),
127 - ($height - $labelHeight - 16),
145 + (int) round(($width * self::PILL_RIGHT_EDGE) - $labelWidth),
146 + (int) round(($height - $labelHeight) / 2),
128 147 0,
129 148 0,
130 149 $labelWidth,
131 150 $labelHeight,