WideImage output as strange characters instead of image - php

I am trying to showing cropped images as thubmnails with WideImage.
I made a function with an array of filenames as parameter ($images) where I produce my html
foreach ($images as $img) {
$pathToThumb = str_replace("/upload/images", "/upload/images/thumbs", $img);
$thumb = WideImage::loadFromFile($pathToThumb)->crop('center', 'center', 150, 100)->output('jpg', 100); ?>
<div class="lingerie">
<a class="fancybox" rel="group" href="<?php print $img; ?>">
<img src="<?php echo $thumb; ?>" alt=""/>
</a>
</div>
<?php } ? ?>
For now, all I get is
����JFIF``���u i$�J�$��]5�����j4���%�o�WEʴ���^[7��|��6�d��P$g�bx�e��wh����N��c��rp=Oz��h�F�Z��"��u8q�oN��la_28�g�����1��2G��1^Uy�EJ��'��|��9F[����Vn��2m�j�i��ַߣ,4���? ����2zp3�P[|���>���1���8$u��+cQ��:x���-�II^r1��{U�+O��T�x��*b��3����zv�m �)b�U��j�+'B�`m������a����T��r���Tq�1�*�����{D_s�!AbG;v��������/i5��u�ݶ]�����M�]�]���#$Z���74"+ar]�-�',�B���J��W�}KY�/7H#��7�3-n�=���v�Ps�3�C~��N��h��j�q��6�����- and so on
What is the reason for these weird digits?

Related

unable to fetch image from the database

I am trying to display images on my web page, the content is getting fetched from my database, but the issue I'm facing is in displaying the image. please, can anyone guide me how should I display the image?
I mean to say the path what I should give
here 'image' is my column name and this is my view
<?php
if( !empty($results) ) {
foreach($results as $row) {?>
<div class="col-sm-4">
<img src="<?php echo base_url('uploads/');$image?>" alt="">
<h3><?php echo $row->title; ?></h3>
<p><?php echo $row->content; ?></p>
</div>
<?php
} ?>
<?php }
?>
Hope this will help you :
Use this : <img src="<?php echo base_url('uploads/'.$row->image);?>" alt="">
The whole code should be like this :
<?php
if( !empty($results) ) {
foreach($results as $row) {?>
<div class="col-sm-4">
<img src="<?php echo base_url('uploads/'.$row->image);?>" alt="">
<h3><?php echo $row->title; ?></h3>
<p><?php echo $row->content; ?></p>
</div>
<?php
} ?>
<?php }
?>
If $image is the column name(which contains image name) then Replace
<img src="<?php echo base_url('uploads/');$image?>" alt="">
with
<img src="<?php echo base_url();?>uploads/<?php echo $row->image;?>" alt="">
If $image has image path then remove ';' and add '.' on echo base_url('uploads/');$image?> line
You issue here is the following code;
<?php echo base_url('uploads/');$image?>
This is because you are not concatenating the string, rather, just saying it's variable name, so, use of the following will provide the output;
<?php echo base_url('uploads/') . $image' ?>
This replaces the semi-colon part way through for a period (.) which is the PHP concatenation operator
Obviously, there is the issue you are not setting $image, which would require (before usage) of;
$image = $row['image_column_name'];
// Or
$image = $row->img_column_name

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 convert a href and img to 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
}

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.

Invalid syntax - Glob image directory scan for carousel

I have the following syntax error with this code:
Warning: natcasesort() expects parameter 1 to be array, boolean given in Website/assets/country-gallery-js.php on line 14
Warning: Invalid argument supplied for foreach() in Website/assets/country-gallery-js.php on line 15
<?php $thumbs = glob("img/thumb/*.{jpg,png,gif}", GLOB_BRACE); ?>
<?php
if(count($thumbs)) {
natcasesort($thumbs);
foreach($thumbs as $thumb) {?>
<li class="item">
<a class="fancybox" rel="gallery1" href="img/large/<?php echo basename($thumb) ?>">
<img src="<?php echo $thumb ?>" class="img-circle" width="100%" alt="" />
</a>
</li>
<?php
}
}
else {
echo "Sorry, no images to display!";
}
?>
I am unsure as to why. The code scans a folder for images to display as a carousel. It scans a thumbnail and large image folder for lightbox. When images are in the folder, it works like a treat.. when the folder is empty it should echo the 'else' text code. Instead it displays this syntax.
Can anyone help me figure this one out and stop the syntax from appearing?
Use is_array instead of count
<?php $thumbs = glob("img/thumb/*.{jpg,png,gif}", GLOB_BRACE); ?>
<?php
if (is_array($thumbs)) {
natcasesort($thumbs);
foreach ($thumbs as $thumb) {
?>
<li class="item">
<a class="fancybox" rel="gallery1" href="img/large/<?php echo basename($thumb) ?>">
<img src="<?php echo $thumb ?>" class="img-circle" width="100%" alt="" />
</a>
</li>
<?php
}
} else {
echo "Sorry, no images to display!";
}
?>
I believe using the braces syntax:
glob("img/thumb/*.{jpg,png,gif}", GLOB_BRACE);
wont work, this probably will:
glob("img/thumb/*.jpg,img/thumb/*.png,img/thumb/*.gif", GLOB_BRACE);
The first step to what you ought to do to check where the problem lies is check what kind of value the variable $thumbs holds. This would have told you that the problem probably lies within the glob function.

Categories