|
...
|
...
|
@@ -36,11 +36,37 @@ class TestController extends BaseController |
|
|
|
$matches = [];
|
|
|
|
// Use preg_match_all to find all src attributes
|
|
|
|
preg_match_all($pattern, $test, $matches);
|
|
|
|
|
|
|
|
$updatedSources = $this->saveBase64Images($matches[1]);
|
|
|
|
// Return an array of all src URLs found
|
|
|
|
return $matches[1];
|
|
|
|
// $newsLogic = new NewsLogic();
|
|
|
|
// $key = $newsLogic->processImage($test);
|
|
|
|
$this->response('success',Code::SUCCESS,$matches[1]);
|
|
|
|
$this->response('success',Code::SUCCESS,$updatedSources);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function saveBase64Images($imageSources) {
|
|
|
|
$updatedSources = [];
|
|
|
|
foreach ($imageSources as $src) {
|
|
|
|
// Check if src is a base64 image
|
|
|
|
if (preg_match('/^data:image\/(png|jpg|jpeg|gif);base64,/', $src, $match)) {
|
|
|
|
$imageType = $match[1]; // Image type (png, jpg, etc.)
|
|
|
|
$base64Data = preg_replace('/^data:image\/(png|jpg|jpeg|gif);base64,/', '', $src);
|
|
|
|
|
|
|
|
// Decode the base64 data
|
|
|
|
$decodedData = base64_decode($base64Data);
|
|
|
|
if ($decodedData === false) {
|
|
|
|
$updatedSources[] = $src; // If decoding fails, keep original src
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Generate a unique filename and path
|
|
|
|
$outputFile = 'images' . uniqid() . '.' . $imageType;
|
|
|
|
$imageUrl = 'http://your-domain.com/' . $outputFile;
|
|
|
|
$updatedSources[] = $imageUrl;
|
|
|
|
} else {
|
|
|
|
$updatedSources[] = $src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $updatedSources;
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
...
|
...
|
|