I've built a function on class Image that retrieves or should retrieve me the image in a binary format. However I just get the error icon when I call that controller method.
I need this done this way, because the images are being sent to an iOS and Android app.
The path of the image is correct (I've double checked it)
I'm using CodeIgniter 2.1.3 and my code looks like this
$images = $this->image->getImageById($database,$id);
$data = fopen($images->path, 'rb');
header('Content-type: image/jpeg');
fpassthru($data);
Any idea on how can I achieve this?
Thank you
I thing you are looking for something like this.
http://www.ehow.com/how_8745742_convert-binary-data-using-php.html
I think this may help you. After getting the result in your model file in an array. In your example $images.
In the view file display it like this <img src="<?php echo $images['path'] ?>" />
Related
I'm showing images from resources/static/images/
The weird thing is if I give the path like "/images/milk.png", it shows the image but if I get name from ${}, it doesn't work.
<img class="card-img-top"
th:src="#{/images/${res.getLogo().getUploadFileName()}}"
th:alt="${res.getLogo().getUploadFileName()}" />
it seems res.getLogo().getUploadFileName() is working well. So it will be replaced like /images/milk.png. But it doesn't show the image...
How can I fix this?
One more thing, I know basic Thymleaf path is resources/templates, but how it recognize image when I gave like "/images/milk.png"
If u want to upload static images
th:src="#{images/} + ${res.logo.uploadFileName}"
if you want to upload dynamic images
th:src="#{https://~~~.com/} + ${id}
I am using magento 1.9.1
I have added media attribute name 'offer_image' in images.
I have also set in attribute set and added image to this attribute in product page.
When I try to get this attribute image on frontent it show error
"Image file was not found"
I am using this code to get image
$this->helper('catalog/image')->init($_product, 'offer_image')->resize(50);
This code work fine if I use thumbnail or small_image.
How should I get custom attribute image, what is wrong with code.
Try to load a product first (looks like you're taking it from a collection):
$product = Mage::getModel('catalog/product')->load($_product->getId());
$this->helper('catalog/image')->init($product, 'offer_image')->resize(50);
<?php if ($_product->getOfferImage() && ($_product->getOfferImage() != 'no_selection')):?>
<img src="<?php echo $_product->getOfferImage();?>">
<?php endif;?>
Loading image using variable containing base64 data in AngularJS
I am trying to find the right way to load a image source from a variable containing base64 encoded image data (for example pulled from a canvas using toDataURL(); ).
At first I just tried it like this:
<img src="{{image.dataURL}}" />
where the image is a scope variable with a variable dataURL containing the base64 data. This is actually working pretty well, the only problem is that I get a 404 error in my console. Something like this:
GET http://www.example.com/%7B%7Bimage.dataURL%7D%7D 404 (Not Found)
Not so pretty. When I tried a more angular style solution like this:
<img data-ng-src="image.dataURL" />
the images are not loading at all.
I made a fiddle which you can find HERE
Any suggestions how to get rid of this error in my console?
EDIT:
Gruff Bunny was right. This <img data-ng-src="{{image.dataURL}}" /> is working...
Working solution can be found HERE
The content of the ng-src needs to be interpolated: Try this:
<img data-ng-src="{{image.dataURL}}"/>
I admit I spent way too much time trying to fix similar problem,
my problem was I had extra brace here (see three braces at end):
ng-attr-src="{{aad.form.imageBase64Temp}}}"
I'm new to MVC 3 and still learning. I'm currently building a static 2 page website which has a different image on both pages but are located in the same place. I have been told that I can use the ViewBag to change this image depending on what page I am on, however I have not got a clue where to begin with applying this to my website.
Any help will be greatly appreciated. Thank You for your time.
On your controller's Action method,make ViewBag or ViewData like this
ViewBag.Imagename="nameofimage";
ViewData["img"]="nameofimage";
On your view, you can make img tag like this
<img src="#ViewBag.Imagename">
or if you have created ViewData
<img src="#ViewData["img"]">
For some reason, it did not work for me when I simply tried using
#ViewBag.BackgroundImage = "~/Content/images/image.jpg"
...
<img src="#ViewBag.BackgroundImage" />
But what did work for me was
#ViewBag.BackgroundImage = "image.jpg"
...
<img src = "~/Content/images/#(ViewBag.BackgroundImage)" />
personally i dont like specifying anything view related in controller, i am using naming convention between action method names and images:
<img src="~/Content/images/#(ViewContext.RouteData.Values["action"].ToString().ToLower())_img.jpg">
and picture name for index action method would be "index_img.jpg"
For those who want use full path in viewbag, use this
#ViewBag.BackgroundImage = "Content/images/image.jpg"
...
<img src="~/#ViewBag.BackgroundImage" />
The reason why hallordylo example not working with full path is missing "~/" in src="..." and this sign "~/" should not be inside ViewBag.
i'm using Ci and i have a form that saves image in a folder. The name of the image is saved in my DB. I want to echo this image.i can retrieve the image name from Db but when i'm echoing this the image it is not showing. I think my controller and model is working fine but there is something wrong with my view.
the part where i'm echoing the image:
<img src="<?php echo base_url();?>uploads/$info[0]->image"></img>
info is the array where the information from the DB(like image name) is saved.
I cannot find my mistake.please help.
I think it's because you're using $info[0]->image outside the PHP tags.
It should be like this:
<img src="<?php echo base_url().'uploads/'.$info[0]->image; ?>" />
One more mistake is how you write the HTML tag IMG