0

I have changed my question. I was wrong. Check it out I'd say.

Is this possible to make a thumbnail if a link contains a .jpg (or .png) extension?

I want to make it a thumbnail automatically if there is a link like http://externalsiteorso.com/blablabla.jpg --> make this a thumbnail.

If it's possible, how can I do this and solve the problem?

I have found this, but it's not for Wordpress, I guess.

$extension = pathinfo($filename, PATHINFO_EXTENSION);

// Read source image
if ($extension == ('jpg' || 'jpeg')) {
    $source_image = imagecreatefromjpeg($filename); 
    return '1';
} else if ($extension == 'png') {
    $source_image = imagecreatefrompng($filename);
    return '2';
} else {
    return 'error';
}
8
  • how do you call this function in your template?
    – Michael
    Aug 3 '13 at 18:19
  • Like this <?php get_first_image(); ?> Aug 3 '13 at 18:36
  • 2
    That function returns an image URL when I test it but that alone is not going to create a thumbnail.
    – s_ha_dum
    Aug 3 '13 at 18:36
  • Well, can someone help me making it a thumbnail? Where do I start, what should I do? Aug 3 '13 at 19:21
  • Whad to you need exactly, can you explain more?
    – Greeso
    Aug 3 '13 at 20:40
0

1) Check out:

http://codex.wordpress.org/Function_Reference/media_sideload_image

2) I found that WP function to be somewhat limited to I wrote my own wrapper class/method. If you want to do the same you're going to need PHP's copy() function

http://us2.php.net/manual/en/function.copy.php

as well as WP's wp_insert_attachment()

http://codex.wordpress.org/Function_Reference/wp_insert_attachment

Unfortunately, I haven't pushed my code to GitHub just yet, so for now you'll have to put something together yourself.

1
  • I am not that good in coding, but will look at it at least. Thanks. Aug 6 '13 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.