function wp_ajax_get_image_colors() { $attachment_id = filter_input(INPUT_POST, 'attachment_id'); $contrast = '255, 255, 255'; $color = '#000000'; if (intval($attachment_id) > 0 && attachment_exists($attachment_id)) { try { $tonesque = new \Tonesque(wp_get_attachment_url($attachment_id)); $contrast = $tonesque->contrast() ? $tonesque->contrast() : $contrast; $color = '#' . $tonesque->color('hex'); } catch (Exception $e) { // Disable tonesque } } echo json_encode(array($contrast, $color)); wp_die(); }