But that just loads whatever image was uploaded from the panel. The problem now is that the images are not resized accordingly and the full 100% of the image is loading which is making the site quite slow.
I want to resize the images and ive been trying width(100) and resize(100) but im not sure how to implement this in the above code without breaking the site.
Pls. turn on debug in your config, I think you have an error in your php syntax. You open a new php tag inside php, because you echo your html tags, which is in fact not good practice.
Let me make this clearer because none of those suggestions seemed to work. I reverted back to my current working code to show you exactly how I’m laying it out and to make sure there are no errors.
This code is spitting out the images perfectly without error. But as above, I want to resize the images to a certain size so the images load faster etc…
No, the toStructure() method does not help here (although you can use it).
As I said above, you have an URL in your content file and you need an image object. The way to transform your URL into an image object should be by using the code I posted above. Have you tried that?
Or change what you are saving to your content file, use the filename instead of the URL and you can use the code I first posted above.
Hm, too bad, maybe the new Asset class only works for images in the assets folder (as its name seems to imply). I thought it could maybe be used for all sorts of images.
Why do you need to use the url instead of just the filename? Would really make things so much easier …
I’m really sorry that it does not work. Yes, changing it to filename would do the job. But maybe someone else here comes up with another idea how to work with the url instead, @lukasbestle?
If you use the filename instead of the URL, you could use this code to fetch the images:
Getting this error : #6 C:\Users\DazdLaptop\Desktop\work\sites#\app\index.php(16): K in C:\Users\DazdLaptop\Desktop\work\sites#\app\site\templates\home.php on line 25
[Fri Jun 3 14:44:18 2016] 127.0.0.1:64207 [500]: / - Uncaught Error: Call to a member function resize() on null in C:\Users\DazdLaptop\Desktop\work\sites#\app\site\templates\home.php:25
This is line 25: <img src="<?php echo $image->resize(100)->url(); ?>">