How to convert a href and img to php? - php

I have this code
echo "<img src='" . $image[0] . "'>";
And this
<img src="images/preview-kv/1.jpg" alt="">
I need to convert this to php with dynamic image... pls

Try these. I have taken Your path and src in variable as example
$path = "/images/preview-kv/1.jpg";
$src = "images/preview-kv/1.jpg";
echo '<img src="'.$src.'" alt="">';
or
<img src="<?php echo $src ?>" alt="">

$image is an array.
Assume $image = array("/images/preview-kv/image1.png","/images/preview-kv/image2.png");
foreach($image as $image_path)
{
?>
<!--$image_value is dynamically changed-->
<img src="<?php echo $image_path; ?>" alt="">
<?php
}

Related

List all image on folder and subfolder and add <a name=" "> for each change folder use php

i want add<a name="each folder change">
try<a name="'$directory'"> front <img
by use this
$directory = "test/*/";
foreach (glob($directory.'*') as $image) {
echo '<img class="img-responsive" src="' . $image . '"/>';
}
and i try have some result like this
<a name="img"><img class="img-responsive" src="test/img/img-000.jpg"></a>
<img class="img-responsive" src="test/img/img-001.jpg">
<a name="image"><img class="img-responsive" src="test/image/image-001.png"></a>
<img class="img-responsive" src="test/image/image-002.png">

display a image that starts with a # in <img> tag

<?php
$imageDir = "";
$images = glob($imageDir . '*.jpg');
foreach ($images as $image) {
?>
<div class="col-lg-3 col-md-4 col-xs-6">
<?php
$name = chop($image, '.jpg');
$filename = $image;
if (file_exists($filename)) {
$taken = "Screenshot Taken: " . date("F d Y H:i:s", filemtime($filename));
}
?>
<a data-gallery="example-gallery" style="text-decoration:none" href="<?php echo $image; ?>" class="d-block mb-4 h-100" data-toggle="lightbox" data-title="Player Name: <?php echo $name; ?>" data-footer="<?php echo $taken; ?>" data-max-width="800" >
<img class="img-fluid img-thumbnail" src="<?php echo $image; ?>" alt="">
<p><?php echo $name; ?></p>
</a>
</div><?php}?>
Hi . i created a image gallery with php . using glob function. but some images wont display , because those images starts with a #(hash) . EX: www.mysite.com/ss/#insta.jpg
iam using tags . is there any other way to view images like this in a
< img> tag
.
Encode the # in your URL
Replacing it with %23 should work

How to display Original image from folder codeignihter

I am trying to display image from its original folder. I want to display the original image in a 1366x768 window.
When I change
<?php $width = 1366;$height = 768; ?>
height in this line, it automaticaly display crop the image in this height and width.
<div class="white_box">
<div class="box-body">
<span class="hide WallHashID"><?php echo $wallpaper->wallpaper_hash; ?></span>
<?php $width = 1366;
$height = 768; ?>
<div class="row">
<div class="col-sm-12">
<div class="wallpaper_image">
<img class="thumbnail img-responsive"
style="width:100%; height:auto; display:block; max-width:<?php echo $width; ?>px;max-height: <?php echo $height; ?>px;"
src="<?php echo $this->image_workshop->crop_image(ORIGINALS_FOLDER_WF . '/' . $wallpaper->wallpaper_image_path, $width, $height, $wallpaper->wallpaper_crop_position, 'thumbnail'); ?>"
alt="<?php echo $wallpaper->wallpaper_name; ?>">
</div>
</div>
</div>
</div>
</div>
<?php } ?>
simply:
<img src="<?php echo base_url(); ?>your folder name /<?php echo $wallpaper->wallpaper_image_path; ?>">
You don't have to use $this->image_workshop->crop_image function, or any other function to process the image. You can use the absolute path of the image and style it with css or with html attributes height and width. For example style it with css:
<img class="thumbnail img-responsive"
style="width:<?php echo $width;?>px; height:<?php echo $height;?>px; display:block; max-width:<?php echo $width; ?>px;max-height: <?php echo $height; ?>px;"
src="<?php echo ORIGINALS_FOLDER_WF . '/' . $wallpaper->wallpaper_image_path ; ?>"
alt="<?php echo $wallpaper->wallpaper_name; ?>">
Or with html tag attributes:
<img class="thumbnail img-responsive"
width="<?php echo $width;?>"
height="<?php echo $height;?>"
src="<?php echo ORIGINALS_FOLDER_WF . '/' . $wallpaper->wallpaper_image_path ; ?>"
alt="<?php echo $wallpaper->wallpaper_name; ?>">
The down side is that you would load the full size image in the browser, where it gets resized. If you care about the information size for the picture, you should create the thumbnails versions as you upload the original. Then use thumbnail version of the image.

Retrieving the images from database and displaying in view

How to retrieve the images if there are multiple images in a single row. I am using this below code to get the images. if there is single image it is displaying. But, I need to display multiple images.
Here is my code:
<?php if(!empty($img['image'])) { ?>
<img src="<?php echo $img['image'];?>" width="100px" height="50px"/>
<?php }else {?>
<img src="image/data/photo/profile1.png" width="100px" height="50px"/>
<?php }?>
I used this function in view for displaying the images
<?php
if(!empty($img['image'])) {
$images = explode($img['image'],',');
foreach($images as $image)
{
print '<img src="' . $image . '" width="100px" height="50px"/>';
}
}else {
print '<img src="image/data/boutique/profile1.png" width="100px" height="50px"/>';
}
?>
or
<?php
if(!empty($img['image'])) {
$images = explode($img['image'],',');
foreach($images as $image)
{
?>
<img src="<?php print $image ?>" width="100px" height="50px"/>
<?php
}
}else {
?>
<img src="image/data/boutique/profile1.png" width="100px" height="50px"/>
<?php
}
?>

How to display an array of multiple images?

I am using this wordpress plugin to upload multiple images. http://wordpress.org/plugins/upload-multiple-image/
It gives me a function that return an array get_multiple_image($post_id). But next I don't know how to display this array?
I want to display all images in this format.
What I should do to get images path in $img1, $img2, $img3, $img4.
<img src="<?php echo $img1; ?>" alt="">
<img src="<?php echo $img2; ?>" alt="">
<img src="<?php echo $img3; ?>" alt="">
<img src="<?php echo $img4; ?>" alt="">
if I do this print_r(get_multiple_image($post_id)); it return this
Array ( [0] => http://localhost/arabian/wp-content/uploads/2014/05/flaconi-bag1.png [1] => http://localhost/arabian/wp-content/uploads/2014/05/hoods-products1.png [2] => http://localhost/arabian/wp-content/uploads/2014/05/product-ring1.png [3] => http://localhost/arabian/wp-content/uploads/2014/05/soud-gloves1.png )
Quick and easy:
// Get images as array
$images = get_multiple_image($post_id);
// Loop over images and echo
foreach($images as $img) {
echo '<img src="'.$img.'" alt="">';
}
Or if you want to set an alternative image text derived from the loop index:
// Loop over images and echo
for($i = 0; $i < count($images); $i++) {
echo '<img src="'.$images[$i].'" alt="Image #'.($i+1).'">';
}
try
$images = get_multiple_image($post_id);
foreach($images as $img) {?>
<img src="<?php echo $img; ?>" alt="">
<?php }?>
or for path you can use array index values
$img1 = $images[0];
$img2 = $images[1];
and so on....
Try this
$AllImages = get_multiple_image($post_id);
foreach($AllImages as $image)
{
echo "<img src='".$image."' alt=''>";
}
<?php
$images=array('http://localhost/arabian/wp-content/uploads/2014/05/flaconi-bag1.png','http://localhost/arabian/wp-content/uploads/2014/05/hoods-products1.png','http://localhost/arabian/wp-content/uploads/2014/05/product-ring1.png','http://localhost/arabian/wp-content/uploads/2014/05/soud-gloves1.png');
print_r($images);
foreach($images as $key){
echo "<img src='".$key."' alt=''>";
}
The output will be,
Array
(
[0] => http://localhost/arabian/wp-content/uploads/2014/05/flaconi-bag1.png
[1] => http://localhost/arabian/wp-content/uploads/2014/05/hoods-products1.png
[2] => http://localhost/arabian/wp-content/uploads/2014/05/product-ring1.png
[3] => http://localhost/arabian/wp-content/uploads/2014/05/soud-gloves1.png
) // your array
and the result
<img src='http://localhost/arabian/wp-content/uploads/2014/05/flaconi-bag1.png' alt=''>
<img src='http://localhost/arabian/wp-content/uploads/2014/05/hoods-products1.png' alt=''>
<img src='http://localhost/arabian/wp-content/uploads/2014/05/product-ring1.png' alt=''>
<img src='http://localhost/arabian/wp-content/uploads/2014/05/soud-gloves1.png' alt=''>
See example
Use this code.
$post_id = get_the_ID();
$MultiImages = get_multiple_image($post_id);
foreach($MultiImages as $img)
{
echo "<img src='".$img."' alt=''>";
}

Categories