CodeIgniter Forums
Add Variable to image_thumb function? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Add Variable to image_thumb function? (/showthread.php?tid=31509)



Add Variable to image_thumb function? - El Forum - 06-22-2010

[eluser]invision[/eluser]
Hi,

The following works beautifully:
Code:
echo image_thumb('www.test.com/uploads/test.jpg', 50, 90);

but this doesn't:

Code:
$posts[img] = "test.jpg";

echo image_thumb('www.test.com/uploads/".$posts[img]."', 50, 90);

Can someone explain what I'm doing wrong.

I'm convinced it's something simple.



Many thanks.


Add Variable to image_thumb function? - El Forum - 06-22-2010

[eluser]Unknown[/eluser]
Try $posts['img'] instead of $posts[img]


Add Variable to image_thumb function? - El Forum - 06-22-2010

[eluser]danmontgomery[/eluser]
You're using a constant as the array index, which I assume should be a string (unless you've defined the 'img' constant for some reason). Also, you're mixing single and double quotes in your concatenation. Single quoted strings are interpreted literally.

Code:
$posts['img'] = 'test.jpg';
echo image_thumb('http://www.test.com/uploads/'.$posts['img'], 50, 90);



Add Variable to image_thumb function? - El Forum - 06-22-2010

[eluser]invision[/eluser]
Code:
Parse error: syntax error, unexpected T_STRING in ...../public_news_id.php on line 5

Line 5 is:
Code:
echo image_thumb('www.test.com/uploads/".$posts['img']."', 50, 90);



Add Variable to image_thumb function? - El Forum - 06-22-2010

[eluser]invision[/eluser]
[quote author="noctrum" date="1277240004"]You're using a constant as the array index, which I assume should be a string (unless you've defined the 'img' constant for some reason). Also, you're mixing single and double quotes in your concatenation. Single quoted strings are interpreted literally.

Code:
$posts['img'] = 'test.jpg';
echo image_thumb('http://www.test.com/uploads/'.$posts['img'], 50, 90);
[/quote]

Thanks for the reply.

Unfortunately, that suggestion doesn't seem to work either.

Instead it makes my file name: 50_90.jpg ??

I definitely have a value in $posts['img'] as I've returned it before using the image_thumb function.


Thanks for your help so far folks.


Add Variable to image_thumb function? - El Forum - 06-22-2010

[eluser]danmontgomery[/eluser]
What is the image_thumb function?


Add Variable to image_thumb function? - El Forum - 06-22-2010

[eluser]invision[/eluser]
Hi,

Here's the function I used: http://jrtashjian.com/blog/image-thumbnail-creation-caching-with-codeigniter/


Thank you!


Add Variable to image_thumb function? - El Forum - 06-22-2010

[eluser]danmontgomery[/eluser]
That's what the function does:

Code:
function image_thumb($image_path, $height, $width)
{
    // Get the CodeIgniter super object
    $CI =& get_instance();

    // Path to image thumbnail
    $image_thumb = dirname($image_path) . '/' . $height . '_' . $width . '.jpg';



Add Variable to image_thumb function? - El Forum - 06-22-2010

[eluser]invision[/eluser]
Eeeek.

Why then should this display the correct image:

Code:
echo image_thumb('www.test.com/uploads/test.jpg', 50, 90);

Or am I missing something obvious?


Thanks for your help with this.


Add Variable to image_thumb function? - El Forum - 06-22-2010

[eluser]danmontgomery[/eluser]
No idea, probably because www.test.com/uploads/test.jpg is an invalid path. The image library only works with local paths.