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

Reply
 
Thread Tools Display Modes
  #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,624
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
  #2  
Old 08-16-2017, 10:36 AM
Pear's Avatar
Pear Pear is offline
Woah man.
 
Join Date: Dec 2013
Location: The Underworld
Posts: 169
Gender: Female
Credits: 45,379
Pear is on a distinguished road
Default

Wow, this is awesome!! :3 Thanks for doing this.
__________________
Noot noot! Gotta get a new signooture. >->
Reply With Quote
  #3  
Old 08-17-2017, 02:01 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 327,405
Hall of Famer is on a distinguished road
Default

Interesting. Note Imagick is a PECL extension that is not available unless it is installed on the server. MysidiaHost has it since I installed Imagick extension for my server, but good chance on other webhosts like x10hosting you cannot do this. Wont be a problem if you run your VPS or Dedicated server though, you will be able to install Imagick yourself.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #4  
Old 08-17-2017, 02:14 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,624
Dinocanid is on a distinguished road
Default

X10 (free version; paid too I'm assuming) offers it along with some other plugins, but it has to be enabled. I'm not sure how it is for other hosts though.
__________________

Last edited by Dinocanid; 08-17-2017 at 05:52 PM.
Reply With Quote
  #5  
Old 10-15-2017, 07:09 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 111,669
Abronsyth is on a distinguished road
Default

I wonder how difficult it'd be to devise a generator/designer for users to use a drop-down or such to make custom pets :0
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #6  
Old 10-15-2017, 07:27 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,624
Dinocanid is on a distinguished road
Default

Actually....

I can give info on how to do this if you want. The only problem with my current method is that I can't seem to have the dropdown make the current color the "active" option after submitting. So "black" would always be at the top of the base color dropdown list for example, even if the user chose "red". It'd be great if anyone figured out a way to fix that though.
__________________
Reply With Quote
  #7  
Old 10-16-2017, 12:05 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 111,669
Abronsyth is on a distinguished road
Default

Well okay then XD
If you could I would absolutely appreciate it! I love systems like that because you can make it easy for users to purchase custom pets (something I want to implement premium currency for lol)
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #8  
Old 10-16-2017, 01:21 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,624
Dinocanid is on a distinguished road
Default

This is what I had on a page called "custompetgenerate.php". It holds the Imagick code:
PHP Code:
<?php
class CustompetgenerateController extends AppController{
    
    public function 
index(){
// Lets setup the database.
$mysidia Registry::get("mysidia");
$custom_session $mysidia->db->select("custom", array(), "uid='{$mysidia->user->uid}'")->fetchObject();
// 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.
$images = array(
        
'http://www.wild-souls.mysidiahost.com/picuploads/den.png',
    
'http://www.wild-souls.mysidiahost.com/picuploads/wolf_images/adult/bases/' $custom_session->base ' base.png',
    
'http://www.wild-souls.mysidiahost.com/picuploads/wolf_images/adult/markings/' $custom_session->marking1 '.png',
    
'http://www.wild-souls.mysidiahost.com/picuploads/wolf_images/adult/markings/' $custom_session->marking2 '.png',
    
'http://www.wild-souls.mysidiahost.com/picuploads/wolf_images/adult/markings/' $custom_session->marking3 '.png',
    
'http://www.wild-souls.mysidiahost.com/picuploads/wolf_images/adult/ranks/' $custom_session->rank '.png',
    
'http://www.wild-souls.mysidiahost.com/picuploads/wolf_images/adult/noses/' $custom_session->nose '.png',
    
'http://www.wild-souls.mysidiahost.com/picuploads/wolf_images/adult/eyes/eyes ' $custom_session->eyes '.png',
    
'http://www.wild-souls.mysidiahost.com/picuploads/wolf_images/adult/shade.png',
    
'http://www.wild-souls.mysidiahost.com/picuploads/wolf_images/adult/lineart.png'
);

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

//Base
$composed_image->setIteratorIndex(2);
$composed_image->compositeImage( new \Imagick($images[1]), \Imagick::COMPOSITE_DSTIN0);
$composed_image->setIteratorIndex(8);
$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 only one flat image.
$image $composed_image->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
$image->setImageFormat('png');

header('Content-type: image/png');
echo 
$image->getImageBlob();
    }
}
?>
I made a new table in the database called "custom". The columns there are similar to how I store the markings and stuff in the regular pet generation script. Each user has their own "session", which is a single column in the database that holds the custom information.
It isn't included here, but each user has a row generated when they register on the site; that row has default values to show a "blank" pet.

PHP Code:
<?php
class CustompetView extends View{
    
    public function 
index(){
        
$mysidia Registry::get("mysidia");
            
$mysidia Registry::get("mysidia");
            
$document $this->document;
            
$custom_session $mysidia->db->select("custom", array(), "uid='{$mysidia->user->uid}'")->fetchObject();
            
$document->setTitle("Create your Character");
        
        
//The width and height must be the same as the image size!
        
$document->add(new Comment("
        <div style='display:flex; align-items:center; justify-content:center;'>
        <iframe src='/custompetgenerate' style='border:none; overflow:hidden; width:800px; height:700px;'></iframe>
        </div>
        "
));
        
$document->add(new Comment("
        <form action='custompet' method='post'>
        <div class ='form-group'>
            <label for='base'>Base Color:</label>
            <select class='form-control' id='base' name='base'>
                <option>black</option>
                <option>black phase</option>
                <option>blue</option>
                <option>chocolate</option>
                <option>clay</option>
                <option>cream</option>
                <option>dark chocolate</option>
                <option>dark cream</option>
                <option>dark grey</option>
                <option>dark red</option>
                <option>faded black</option>
                <option>faded blue</option>
                <option>faded gold</option>
                <option>gold</option>
                <option>grey</option>
                <option>isabella</option>
                <option>ivy</option>
                <option>light cream</option>
                <option>light grey</option>
                <option>moss</option>
                <option>off-white</option>
                <option>red</option>
                <option>saffron</option>
                <option>sand</option>
                <option>white</option>
            </select>
            <label for='eyes'>Eye Color:</label>
            <select class='form-control' id='eyes' name='eyes'>
                <option>blue</option>
                <option>gold</option>
                <option>green</option>
                <option>red</option>
                <option>violet</option>
            </select>
            </div>
            <label for='nose'>Nose Color:</label>
            <select class='form-control' id='nose' name='nose'>
                <option>black butterfly</option>
                <option>black</option>
                <option>blue</option>
                <option>dudley</option>
                <option>liver butterfly</option>
                <option>liver</option>
                <option>pink</option>
                
            </select>
        Marking 1: <select class='form-control' id='marking1' name='marking1'>
                <option>empty</option>
                <option>agouti</option>
                <option>black overfur</option>
                <option>brown overfur</option>
                <option>harlequin</option>
                <option>irish</option>
                <option>piebald</option>
                <option>red points</option>
                <option>snowflake</option>
                <option>tan eyes</option>
                <option>urajiro</option>
                <option>white socks</option>
                <option>white tips</option>
                <option>white trim</option>
                <option>white underfur</option>
            </select>
        <p><p>
        <input type='submit'>
        </form>
        "
));
        
        if (
$_SERVER["REQUEST_METHOD"] == "POST") {
        
$base $_REQUEST['base'];
        
$eyes $_REQUEST['eyes'];
        
$mark1 $_REQUEST['marking1'];
        
$nose $_REQUEST['nose'];
        
$mysidia->db->update("custom", array("base" => $base"eyes" => $eyes"marking1" => $mark1"nose" => $nose), "uid = '{$mysidia->user->uid}'");

            }
        
    }
}
?>
This is where the interface is. (custompet.php was basically the same as blank.php, so it wasn't worth posting here.) Each time the user clicks "submit", their dropdown selections are saved to the database and the image updates to reflect what they chose. The way this is set up, the user's customization is "saved" and it will remain the same if they leave the page and come back. With some tweaking, it should be possible to add another button saves the customization as an actual adoptable.
__________________
Reply With Quote
  #9  
Old 10-16-2017, 04:27 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 111,669
Abronsyth is on a distinguished road
Default

Thank you!!

So knowing how it saves in the database I think I can fix the drop-down selection problem.

What needs to be done is modify the first (aka default) option to reflect what the user has listed in the database. It'll look sort of like this I think:
HTML Code:
<option selected>{$selectedbase}</option> 
<option>black</option>
<option>brown</option>
<option>...and so on...</option>
First we'd need to define $selected, which is easy enough;
PHP Code:
$selectedbase $mysidia->db->select("custom", array("base"), "uid='{$mysidia->user->uid}'")->fetchColumn(); 
I haven't tested it at all yet, haha, but I do think that it'd work along those lines!

And thank you again, Dinocanid!!!
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #10  
Old 11-06-2017, 10:39 AM
gwynmil's Avatar
gwynmil gwynmil is offline
Member
 
Join Date: Sep 2017
Location: UK
Posts: 25
Gender: Female
Credits: 3,499
gwynmil is on a distinguished road
Default

OK, finally giving this a try (feeling slightly more confident than last week, though the breeding script edits will still be offloaded to you, haha. I'm afraid to touch that stuff yet).

edit: never mind, figured out first issue. Reading that TGL thread was very helpful.

Still getting a blank image though. Syntax error maybe? I removed the composite_dstin bit 'cause that command isn't needed here.

PHP Code:
<?php
class GriffimageController extends AppController{
    
    public function 
index(){

$mysidia Registry::get("mysidia");

$fullurl $_SERVER['HTTP_REFERER'];
$cleanaid  end(explode('/',trim($fullurl,'/')));

$pet $mysidia->db->select("owned_adoptables", array(), "aid='$cleanaid'")->fetchObject();

$images = array(
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/legs/' $pet->legs '.png',
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/outer2/' $pet->outer2 '.png',
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/outer1/' $pet->outer1 '.png',
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/inner2/' $pet->inner2 '.png',
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/inner1/' $pet->inner1 '.png',
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/hind/' $pet->hind '.png',
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/fore/' $pet->fore '.png',
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/horns/' $pet->horns '.png',
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/beak/' $pet->beak '.png',
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/eyes/' $pet->eyes '.png',
    
'http://griffusion.elementfx.com/picuploads/griffimages/' $pet->type '/' $pet->gender '/' $pet->currentlevel '/line.png'
);

$composed_image = new \Imagick($images);

$image $composed_image->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
$image->setImageFormat('png');

header('Content-type: image/png');
echo 
$image->getImageBlob();
    }
}
?>
Example body part url: http://griffusion.elementfx.com/picu.../fore/blue.png
Linearts are in the level folder: http://griffusion.elementfx.com/picu...h/f/5/line.png

Sorry for the constant questions, haha. You've been amazingly helpful lately.

Last edited by gwynmil; 11-06-2017 at 01:01 PM.
Reply With Quote
Reply

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 09:12 AM.

Currently Active Users: 444 (0 members and 444 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