• Hi,

    I’m trying to generate grayscale thumbnails automatically, which will then be replaced by a coloured version when rolled over.

    I’ve found a plugin that will generate grayscale thumbnails called thumbGen. This works fine if you specify the url of the image, however I want it to use the first image from the post. The code for thumbGen is: <?php thumbGen(imageURL); ?>

    I all ready have a function to get the first image of a post, which is working fine on its own.

    Somehow I need to combine the two so that the first post image is passed through the thumbGen plugin, something like this:

    <?php thumbGen(<?php echo catch_that_image() ?>); ?>

    Obviously just sticking the catch_that_image function in there doesn’t work, but I don’t know how to do it properly.

    Advice is much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • <rant>wordpress coding style confuses beginners</rant>

    You should do some reading to get some foundation on PHP programming, it will help avoid this kind of mistake ??

    The <?php tags indicates the start of php code block and ?> indicates the end. So you shouldn’t have another set of php tags within one set. WordPress coding style makes it confusingly unobvious because of the intermingled PHP code blocks scattered all over.

    The correct syntax, but not necessarily working depending on the output of catch_that_image, should be <?php thumbGen(catch_that_image()); ?>

    Assuming there is no outer PHP block around that.

    Have you tried the example code?. It makes just that:

    <?php
    $img="";
    $args = array(
        'post_parent'    => $post->ID,
        'post_type'      => 'attachment',
        'numberposts'    => 1,
        'post_mime_type' => 'image'
    );
    $attachs = get_posts($args);
    if ($attachs) {
        $img=wp_get_attachment_image_src($attachs[0]->ID,'full');
    }
    if(!empty($img)){
    ?>
    <img src='<?php thumbGen($img[0],171,56,"effect=grayscale"); ?>' alt='' />
    <?php
    }
    ?>

    If you want the image to be in grayscale you’ll have to send the argument in the fourth parameter, as shown in the example.

    Good luck!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Grayscale thumbnails using thumbgen’ is closed to new replies.