I want to get and display PHP-generated images (jpg) using alamofireimage in swift3.
Assume
·Alamofireimage itself is operating normally.
·If it is a static jpg file on the server, it can be retrieved without any problems.
·The PHP output image is also generated successfully when you check it from your browser.
Below is the code for the part you are trying.
Swift side action
//ViewController
// override func viewDidLoad(){
//(1) Direct link to JPG image works.
self.imgURL="https://.../path/sample.jpg"
//(2) For links to PHP (generated image), the image cannot be retrieved.
self.imgURL="https://.../path/output.php?param=sample"
let ImageURL = NSURL (string:self.imgURL) !
Let placeholderImage=UIImage(named: "myplaceholder.png")!
self.mapImageView.af_setImage(withURL:ImageURL as URL, placeholderImage:placeholderImage)
PHP-side processing
#PHP dynamically outputs JPG images
# 今回 This time we are generating JPG from SVG data.
$image=newImagick();
$image->readImageBlob($SVGData);
$image->setImageFormat("jpg");
header('Content-Type:image/'.$image->getImageFormat());
echo$image;
How can I get the image from PHP (alamofireimage)?
Thank you for your advice.
I don't know which header the alamofireimage uses for processing, but the Content-Type is
$image->setImageFormat("jpg");
header('Content-Type:image/'.$image->getImageFormat());
The image/jpg output appears when you run . If the output is only for the jpg image,
header('Content-Type: image/jpeg');
I wonder if the output is good because it is fixed.
If necessary, I will give you the image name and image size in the header.
header('Content-Disposition: attachment; filename="img name"";
header('Content-Length:'.$image->getImageSize());
© 2024 OneMinuteCode. All rights reserved.