In my website I got like 10GB of images but 90% of that images are really huge. And what I need is to render them in thumbnail, but I don't want to create thumbnail for each image. And I create a code for resize it and print it in PHP and just call the PHP.
But I also need the follow data, that I don't know how to add it.
<img src="<? echo $img; ?>" width="<? echo $width; ?>" height="<? echo $height; ?>" alt="<? echo $descr; ?>" tag='<? echo $tags; ?>' id="img_idea"/>
How could I add all this information?
Thnaks
If you are concerned with Bandwidth you'll want to make SMALLER new copies of your big images when they are uploaded.
If you are also concerned with space, you can create a page (i.e. www.mysite.com/image.php?imgid=133) that will look up the images, check for the smaller version, create it if it does not exist, then serve the smaller version.
Check out PHP GD and the numerous plugins that stem from it to figure out how to resize the images.
If you're NOT concerned with Bandwidth, you can wrap your img in a div, then apply the desired width/height to the div and max-width: 100%; and max-height: 100% to the img.
Related
So, a single item looks like this:
$img = "http://example.com/gallery/main.php?g2_view=core.DownloadItem&g2_itemId=12345";
<a href="<?php echo $img ?>">
<img src="<?php echo $img ?>" loading="lazy" class="rounded" />
</a
So, I'm supplying the same thing to both <a> and `' elements. While the latter is able to render thumbnails from it, the lightbox itself is not opening the (large, or better said, same image) in place, as expected, but it rather displays the image in a regular PHP page.
I've been able to pinpoint the cause by testing with a "real" image URL (ie. with .jpg or .png extension at the end). In that case, large image will be loaded in lightbox.
So my question is how to get a temp (real) image to be used in <a> element from what I'm trying to use currently?
I'm trying to use PHP to retrieve a list of recent uploaded videos from a Youtube channel however the thumbnails are all in 4:3 format with black borders at the top and bottom.
I am using the following to retrieve the thumbnails:
$thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;
and this to import them:
<img src="<?php echo $thumbnail;?>"/>
The youtube API website and various other Q&A websites say you can use the variable
yt:name='mqdefault'
to retrieve the 16:9 thumbnails with no borders, however I have no clue where to incorporate this into the PHP?
http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
You would need you url to look similar to one of those.
Not sure what:
(string)$media->group->thumbnail[0]->attributes()->url; is returning but I would take a look at that URL and make sure it resembles something similar to above.
For you below example you want you URL to resemble this.
http://img.youtube.com/vi/0GQPoyMr30o/mqdefault.jpg
http://img.youtube.com/vi/0GQPoyMr30o/maxresdefault.jpg
Try doing something like this:
<?php
$thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;
$thumbnail = str_replace('0.jpg', 'mqdefault.jpg', $thumbnail);
?>
<img src="<?php echo $thumbnail; ?>" />
I'm working on an image-heavy wordpress project. I use the following code to set the image width and height for the medium and large image sizes, and set both to hard crop mode. These values are the same as the current values for Settings>Media: (code based on this documentation)
update_option('medium_size_w', 335);
update_option('medium_size_h', 400);
update_option('medium_crop', 1);
update_option('large_size_w', 690);
update_option('large_size_h', 400);
update_option('large_crop', 1);
When I upload and insert an image using the in-post insert media button with the medium size option, everything works as expected. However, when I upload and insert a large image, I get the following markup:
<a href="http://saltdesignpdx.com/wp-content/uploads/2013/04/TCK7765.jpg">
<img src="http://saltdesignpdx.com/wp-content/uploads/2013/04/TCK7765-690x400.jpg"
alt="_TCK7765" width="540" height="313" class="alignnone size-large wp-image-53" />
</a>
Note the width="540" height="313" part of that markup. It should be width="690" height="400".
Does anyone know what's going on here, or some steps I could take to diagnose it?
Edit: I just tried switching the theme to twenty-eleven, uploading a new image, and inserting it into a post. This was the result:
<a href="http://saltdesignpdx.com/wp-content/uploads/2013/04/IMG_0729.jpg">
<img src="http://saltdesignpdx.com/wp-content/uploads/2013/04/IMG_0729-690x400.jpg"
alt="IMG_0729" width="584" height="338" class="alignnone size-large wp-image-57" />
</a>
Weird. Changing the theme changed the dimensions specified in the img tag, but they still don't match the actual size of the image.
The problem was content_width. Thanks, Fred, for the suggestion to search for 540 also.
After setting content_width to match my actual maximum content width, the size attributes wordpress provides in the <img> tag are now correct.
I am trying to create a function where the user can click an image and a bigger one will load in a small popup window. I already have the bigger image in the system so it merely needs to load the image but in a window the right size!
Any ideas how I can achieve this?
Thanks.
You might want to look into using one of many js lightbox solutions
http://leandrovieira.com/projects/jquery/lightbox/ for example
Look into window.open. That will let you open a new window of a specified height and width, you just need to do something like:
window.open("<?php echo $url; ?>", "_blank",
"height=<?php echo $height;?> width=<?php echo $width; ?>")
You can get the image size in PHP with getimagesize
I created a responsive javascript only lightbox (no jquery needed) where you can pass links to the bigger image. So your thumbnail HTML should look like this, where your thumbnail-picture goes into the src attribute and the link to the bigger picture goes into the data-jslghtbx attribute:
<img class="jslghtbx-thmb" src="img/lightbox/thumbnail-picture.jpg" alt="" data-jslghtbx="img/big-picture.jpg">
You can also use the gallery function via the data-jslghtbx-group attribute to show multiple pictures, but be sure to hide all image elements (except the thumbnail which triggers the lightbox) via display: none;. Visit github for full documentation. Hope this helps!
I have a web page that displays images that I don't know their size in advance. I was trying to use the GD functions to make the script resize and crop the images from me " Just before they are displayed.. I don't need caches" but I failed.
I need a script that I can call like this
<img src="display.php?src=blablabla&height=100&width=200" ?>
or even by calculating the width and height of css to preserve the proportions and make the image touch the box from inside like
<img src="blabla.jpg" style="height:<?php echo $height; ?>; width:<?php echo width; ?>" />
I don't need any sort of caching. How can I do that ?
WideImage rlz! :)
The resize's like that:
header('Content-type: image/jpeg');
echo WideImage::load('image.jpg')->resize(200, 100)->asString('jpg', 80);
// image.jpg resized at 200x100 with 80% of quality
You'll need to use the first style. Because this would be happening server-side, you can't check the CSS to get the desired size.
You just need to use the GD functions to open the appropriate file, use imagecopyresampled() to resize it, and then output to the buffer using imagejpeg. Don't forget to set the right headers:
header('Content-type: image/jpeg');
OR phpthumb http://phpthumb.sourceforge.net/
Demo is available at: http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php
You are looking for TimThumb (Demo | Source Code):
Simply copy the source code into a new
document called ‘timthumb.php’, place
it in a folder on your site (ex:
/scripts/) and call the image like
this:
<img src="/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1" alt="">