Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Addons and Modifications > Mys v1.3.x Mods

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-15-2017, 12:51 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,652
Dinocanid is on a distinguished road
Default Dynamically Generated Images Addon

Before I begin, special thanks to Digital and Hare over at TGL. I couldn't have done this without them! (Link to original discussion)

What this does: This addon will use Imagick (a.k.a ImageMagick) to layer multiple images, compress them into one, and display them wherever you'd like without using AJAX. This can be used for backgrounds, decors, or dynamically generated pets. (Great for breeding sites!) I recommend you read the entire tutorial and then tailor it to fit your needs rather than following along right away.

-Getting the images ready-
As an example, I have my pet's layers saved as separate, transparent png images. Make sure they appear on top of each other properly! Also make sure all of the images are the same size, don't crop them! This can easily be checked in any art/art editing program that allows layers (I use FireAlpaca). Then it's on to the folder structure. You can set in up in the picuploads folder. This is how mine looks:
  Spoiler: My folder structure 
  • picuploads
    • wolf_images
      • pup
        • bases
        • eyes
        • markings
      • adult
        • bases
        • eyes
        • markings


-Step 0-
On x10host: Installing Imagick is easy for you. Just navigate to CPanel and find "select PHP version". Click on it and look for the "imagick" plugin (should be in the second column). Check the box, hit save, and you're done! (If you're not on x10, your host might have this too. If not, continue to the second option below)
On XAMPP/Other hosts: Whether you're using a XAMPP server or a host that doesn't allow the above, follow this tutorial: Link. If not using XAMMP, make sure you search google on how to install imagick on your host before taking this route! It could be different based on your host.

-Step 1-
Navigate to phpMyAdmin and get some columns set up in owned_adoptables. Use consistent naming conventions! It will make your life 100% easier in the long run I promise you. For the sake of this tutorial, I'm going to use my column names and code as an example. Here are the new columns I made with the names:


-Step 2-
Navigate back to the root folder and make a new php file to hold the Imagick code. (I called mine wolfimage.php) Inside, this is how it looks:
PHP Code:
<?php
header
('Content-type: image/png');
// Lets setup the database.
$mysidia Registry::get("mysidia");

//A not-so-clean way to get the wid of the parent page
$fullurl $_SERVER['REQUEST_URI'];
$scrub explode('/',trim($fullurl,'/'));
$cleanwid  end($scrub);

$pet $mysidia->db->select("wolves", array(), "wid='$cleanwid'")->fetchObject();
    if(
$pet->age >= 12){
        
$images = array(
            
'http://wild-souls.mysidiahost.com/picuploads/den.png',
            
"http://wild-souls.mysidiahost.com/picuploads/wolf_images/adult/bases/" $pet->base "base.png",
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/adult/markings/' $pet->marking4 '.png',
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/adult/markings/' $pet->marking3 '.png',
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/adult/markings/' $pet->marking2 '.png',
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/adult/markings/' $pet->marking1 '.png',
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/adult/ranks/' $pet->rank '.png',
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/adult/eyes/eyes' $pet->eyes '.png',
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/adult/shade.png',
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/adult/lineart.png'
        
);
    }
    else{
        
$images = array(
            
'http://wild-souls.mysidiahost.com/picuploads/den.png',
            
"http://wild-souls.mysidiahost.com/picuploads/wolf_images/pup/bases/" $pet->base "-base-pup.png",
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/pup/markings/' $pet->marking1 '-pup.png',
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/pup/eyes/eyes' $pet->eyes '-pup.png',
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/pup/shade-pup.png',
            
'http://wild-souls.mysidiahost.com/picuploads/wolf_images/pup/lineart-pup.png'
        
);
        
    }
// Remember to order these in reverse, the last element in the array should always be the top layer you will see (usually lineart). All images should be the same dimensions. The first element in the array is [0], not [1]!!!!


// This creates the Imagick class that we will use.
$composed_image = new \Imagick($images);

// Base
if($pet->age >= 12){
$composed_image->setIteratorIndex(2);
$composed_image->compositeImage( new \Imagick($images[1]), \Imagick::COMPOSITE_DSTIN0);
$composed_image->setIteratorIndex(3);
$composed_image->compositeImage( new \Imagick($images[1]), \Imagick::COMPOSITE_DSTIN0);
$composed_image->setIteratorIndex(4);
$composed_image->compositeImage( new \Imagick($images[1]), \Imagick::COMPOSITE_DSTIN0);
$composed_image->setIteratorIndex(5);
$composed_image->compositeImage( new \Imagick($images[1]), \Imagick::COMPOSITE_DSTIN0);
$composed_image->setIteratorIndex(6);
$composed_image->compositeImage( new \Imagick($images[1]), \Imagick::COMPOSITE_DSTIN0);
$composed_image->setIteratorIndex(8);
$composed_image->compositeImage( new \Imagick($images[1]), \Imagick::COMPOSITE_DSTIN0);
}
else{
    
$composed_image->setIteratorIndex(2);
$composed_image->compositeImage( new \Imagick($images[1]), \Imagick::COMPOSITE_DSTIN0);
$composed_image->setIteratorIndex(4);
$composed_image->compositeImage( new \Imagick($images[1]), \Imagick::COMPOSITE_DSTIN0);
}

// As you see above, by calling setIteratorIndex(), you switch your "working layer" to the layer you wish to modify.
// Now lets flatten it and display it. This creates a new Imagick instance to work with with only one flat image.
$image $composed_image->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
$image->setImageFormat('png');

echo 
$image->getImageBlob();
?>
-Step 3-
We're just about done! Don't believe me? Next I went to myadoptsview.php (called denview.php for me) and used this to get the image:
PHP Code:
$document->add(new Comment("<img src ='/wolfimage/{$wid}' height='auto' width='75%'>")); 
The size is the full size of my image, and the full http:// is required! It is used in place of $adopt->getImage and instead shows the dynamically generated version. Here are my two lovely generated puppies:



-Finale-
-Imagick and relative paths-
Imagick for PHP 5.4 does not like relative paths, so absolute paths are required for it to work. I'm not sure if that's still the case with newer PHP versions.
-Playing with Imagick-
The markings images for my wolves are actually really messy and don't fit inside the lines. I fixed this by using COMPOSITE_DSTIN, which does it for me. (Yay, laziness! The reason the base itself doesn't completely fit in the lines is because I neglected to do so on the image itself, not because of imagick)
To use your own filters, just poke around here and try them out to see which ones you like: Clicky.
-Backslashes vs. Forwardslashes-
If you use XAMPP/WAMPP like me, you'll have to use double backslashes. If you're operating online, then you use single forwardslashes like any other URL.
-Need help tailoring?-
Just let me know in the comments if things are going wrong. I can help you out with it.
__________________

Last edited by Dinocanid; 12-17-2017 at 04:08 PM.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:23 PM.

Currently Active Users: 461 (0 members and 461 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636