adamsevera Posted April 29, 2015 Share Posted April 29, 2015 Hello, can someone please help me out with the following. how can i Echo "text" only if attached thumbnail resolution is over 500px x 500px in wordpress? I want to echo a link if the attached thumbnail is bigger than the specified image resolution. Thanks. Link to comment https://forums.phpfreaks.com/topic/295928-how-can-i-echo-text-only-if-attached-thumbnail-resolution-is-over-500px-by-500px-in-wordpress/ Share on other sites More sharing options...
Psycho Posted April 29, 2015 Share Posted April 29, 2015 I don't use wordpress, so the actual implementation is up to you. But, you can check the size of an image using the function getimagesize(). Example list($width, $height) = getimagesize('path/to/image/imagename.jpg'); if($width>500 || $height>500) { echo "Image is greater than 500 x 500"; } Link to comment https://forums.phpfreaks.com/topic/295928-how-can-i-echo-text-only-if-attached-thumbnail-resolution-is-over-500px-by-500px-in-wordpress/#findComment-1510221 Share on other sites More sharing options...
adamsevera Posted April 29, 2015 Author Share Posted April 29, 2015 i Tried the following it returns "list($width, $height)" $img_url is hotlink for full size thumbnail image <?php list($width, $height) = getimagesize('$img_url'); if($width>500 || $height>500) {echo "Image is greater than 500 x 500";} ?> I don't use wordpress, so the actual implementation is up to you. But, you can check the size of an image using the function getimagesize(). Example list($width, $height) = getimagesize('path/to/image/imagename.jpg'); if($width>500 || $height>500) { echo "Image is greater than 500 x 500"; } Link to comment https://forums.phpfreaks.com/topic/295928-how-can-i-echo-text-only-if-attached-thumbnail-resolution-is-over-500px-by-500px-in-wordpress/#findComment-1510224 Share on other sites More sharing options...
maxxd Posted April 29, 2015 Share Posted April 29, 2015 From the Codex: wp_get_attachment_image_src(). $returnValue[1] = width, [2] = height. Link to comment https://forums.phpfreaks.com/topic/295928-how-can-i-echo-text-only-if-attached-thumbnail-resolution-is-over-500px-by-500px-in-wordpress/#findComment-1510285 Share on other sites More sharing options...
gizmola Posted April 29, 2015 Share Posted April 29, 2015 One caveat. If what you have in your template is something like this: <img src="/path/to/helper.php"> Then this is not going to work. The template itself would need the code to determine what to output. Link to comment https://forums.phpfreaks.com/topic/295928-how-can-i-echo-text-only-if-attached-thumbnail-resolution-is-over-500px-by-500px-in-wordpress/#findComment-1510315 Share on other sites More sharing options...
Psycho Posted April 29, 2015 Share Posted April 29, 2015 This line of code is invalid list($width, $height) = getimagesize('$img_url'); If you put a variable in a double quoted string it will be parsed as the value of the variable. But, if you put a variable in a single quoted string, as shown above, the characters of the variable name will be interpreted as those literal characters! Example: $img_url = "\path\to\image\imagename.jpg"; echo "$img_url"; //Output: \path\to\image\imagename.jpg echo '$img_url'; //Output: $img_url In your usage, no quotes are even needed, just use this list($width, $height) = getimagesize($img_url); Link to comment https://forums.phpfreaks.com/topic/295928-how-can-i-echo-text-only-if-attached-thumbnail-resolution-is-over-500px-by-500px-in-wordpress/#findComment-1510319 Share on other sites More sharing options...
adamsevera Posted April 30, 2015 Author Share Posted April 30, 2015 Found a Solution <? $imgdata = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); $imgurl = $imgdata[0]; // the url of the thumbnail picture $imgwidth = $imgdata[1]; // thumbnail's width $imgheight = $imgdata[2]; // thumbnail's height ?> <? if ($imgwidth >= 500 || $imgheight >= 500){ echo "TEXT"; } ?> Link to comment https://forums.phpfreaks.com/topic/295928-how-can-i-echo-text-only-if-attached-thumbnail-resolution-is-over-500px-by-500px-in-wordpress/#findComment-1510405 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.