public function ajax_convert_image() {
// ... existing validation code ...
// New resolution handling
$resolution = isset($_POST['resolution']) ? sanitize_text_field($_POST['resolution']) : 'medium';
// Process image with resolution-specific settings
try {
$image_path = $_FILES['image']['tmp_name'];
$svg_content = $this->process_image($image_path, $layers, $resolution);
wp_send_json_success([
'svg' => $svg_content,
'layers' => $layers,
'resolution' => $resolution
]);
} catch (Exception $e) {
wp_send_json_error([
'message' => $e->getMessage()
]);
}
}
private function process_image($image_path, $layers, $resolution) {
// Load and resize image
$image = $this->load_image($image_path);
// Resolution-specific processing
$image = $this->resize_for_resolution($image, $resolution);
// Convert to grayscale
imagefilter($image, IMG_FILTER_GRAYSCALE);
// Generate SVG
return $this->generate_svg($image, $layers, $resolution);
}
private function resize_for_resolution($image, $resolution) {
$orig_width = imagesx($image);
$orig_height = imagesy($image);
// Resolution-based scaling factors
$scale_factors = [
'low' => 0.25, // 25% of original size
'medium' => 0.5, // 50% of original size
'high' => 0.75, // 75% of original size
'ultra' => 1.0 // Full original size
];
$scale = $scale_factors[$resolution] ?? 0.5;
$new_width = round($orig_width * $scale);
$new_height = round($orig_height * $scale);
// Create new image
$resized = imagecreatetruecolor($new_width, $new_height);
// Enable alpha blending
imagealphablending($resized, false);
imagesavealpha($resized, true);
// Resize
imagecopyresampled(
$resized, $image,
0, 0, 0, 0,
$new_width, $new_height,
$orig_width, $orig_height
);
return $resized;
}
private function generate_svg($image, $layers, $resolution) {
$width = imagesx($image);
$height = imagesy($image);
// Resolution-based step sizes
$step_sizes = [
'low' => 10, // Larger steps, less detail
'medium' => 5, // Balanced
'high' => 3, // More detail
'ultra' => 2 // Maximum detail
];
$step_size = $step_sizes[$resolution] ?? 5;
$svg = [
sprintf('';
return implode("\n", $svg);
}
Parse error: Unmatched '}' in /www/htdocs/w01e3ab4/cnc-corner.org/wp-content/plugins/wp-2.5-carver-v3/includes/class-wp-25d-carver-shortcode.php on line 111