Jump to content

KittHaven

Members
  • Posts

    6
  • Joined

  • Last visited

  • Days Won

    1

KittHaven last won the day on July 5 2023

KittHaven had the most liked content!

Gamer Information

  • Sites
    None at the moment

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

KittHaven's Achievements

Rookie

Rookie (6/21)

  • Dedicated Rare
  • First Post Rare
  • Reacting Well Rare
  • Conversation Starter Rare
  • One Month Later

Recent Badges

1

Reputation

  1. Thanks, I managed to fix it! You gave me the idea by suggesting to print the output but turns out the code was in the wrong file lol. I was trying to compare the two values in the file that generates the image when really it needs to be done where the image is displayed so if the 2 timestamps don't match it forces the image to regenerate. It's working now! 😄
  2. Thank you but I couldn't get it working and I'm pretty sure it's because the image gets generated new every time the page loads, it wasn't being stored anywhere. So I kept working at writeimage and managed to get that working, and now can call the image directly from the files. Just working on unlinking and updating the image when it's changed now :3 Though for some reason my if statement isn't working for comparing the last updated and img last updated fields and unlinking if they both don't match... not sure why. I might leave it here in case anyone has an idea, instead of making a new thread. if($adopt->lastupdate !== $adopt->imglastupdate && file_exists('C:\\wamp64\\www\\beanpets\\images\\adopts\\pets\\' . $adopt->aid . '.png')){ unlink('C:\\wamp64\\www\\beanpets\\images\\adopts\\pets\\' . $adopt->aid . '.png'); } else{ $mysidia->db->update("owned_adoptables", ["lastupdate" => $timestamp, "imglastupdate" => $timestamp], "aid = '{$adopt->aid}'"); $storepath = 'C:\\wamp64\\www\\beanpets\\images\\adopts\\pets\\' . $adopt->aid . '.png'; $image->writeImage($storepath); } I can't see any reason why it wouldn't work, but I'm still teaching myself PHP so maybe I'm just overlooking it 😅
  3. Hello! I'd like to cache images generated on my site with Imagick but I'm unsure how. I've never really worked with caching before lol. Currently loading times on the owned adoptables page is like 10~ seconds for 7 pets... which isn't ideal. The images are currently quite large though as I'm not bothered by the look of the page just yet so just have the images printing out. I have tried to put the below into my .htaccess file but it won't affect my Imagick images. I'm not sure if that's because the images don't have a png extension on them or what. Or do I need to wrap the generation in something to check if it's cached...? (When you go to the URL it displays as 'http://127.0.0.1/beanpets/adoptimage/view/3' and adding .png to the end breaks it) So I'm unsure if that would affect it maybe not seeing it as a png? Even though Imagick does set the image format to PNG. <ifModule mod_headers.c> # Turn on Expires and set default expires to 3 days ExpiresActive On ExpiresDefault A259200 # Set up caching on media files for 1 month <filesMatch ".(ico|gif|jpg|jpeg|png|flv|pdf|swf|mov|mp3|wmv|ppt)$"> ExpiresDefault A2419200 Header append Cache-Control "public" </filesMatch> # Set up 2 Hour caching on commonly updated files <filesMatch ".(css)$"> ExpiresDefault A7200 Header append Cache-Control "private, must-revalidate" </filesMatch> # Force no caching for dynamic files <filesMatch ".(xml|txt|php|htm|html|js)$"> ExpiresDefault A0 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" </filesMatch> </ifModule> I have also tried using: ExpiresByType image/png A2592000 Neither seem to work. I'm also unsure how to even check if the browser is caching things anyway, and just not caching my Imagick images. My imagick code, adoptimagecontroller.php (using mysidia framework): <?php namespace Controller\Main; use Resource\Core\AppController; use Resource\Core\Registry; class AdoptimageController extends AppController{ public function __construct(){ parent::__construct(); } public function index(){ $mysidia = Registry::get("mysidia"); } public function view($aid){ $mysidia = Registry::get("mysidia"); header('Content-type: image/png'); //A not-so-clean way to get the id of the parent page $fullurl = $_SERVER['REQUEST_URI']; $scrub = explode('/',trim($fullurl,'/')); $cleanaid = end($scrub); $adopt = $mysidia->db->select("owned_adoptables", array(), "aid='$cleanaid'")->fetchObject(); if($adopt->species == "cat_bean"){ if($adopt->currentlevel == 5){ $images = array( //(Snipped because of length) ); } } // This creates the Imagick class that we will use. $composed_image = new \Imagick($images); $clut = new \Imagick(); if($adopt->species == "cat_bean"){ if($adopt->currentlevel == 5){ //(Snipped because of length) } } $image = $composed_image->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN); $image->resizeImage(600,600, \imagick::FILTER_LANCZOS, 1); $image->setImageFormat('png'); echo $image->getImageBlob(); } } ?> Ideally I really want to cache images and not store them, partly for eventual performance, and partly because I couldn't get writing images to work and this is the ideal solution anyway lol. Thanks for any help! If you need more files then I can provide them.
  4. Decided to give it another shot this morning and I fixed it! Ended up working with this (literally just changing Imagick to ImagickPixel *cri*): $composed_image->setIteratorIndex(10); $clut->newImage(1, 1, new \ImagickPixel("$custom_session->body_colour1")); // Colours the body $composed_image->clutImage($clut); $clut->destroy(); $composed_image->compositeImage( new \Imagick($images[10]), \Imagick::COMPOSITE_DSTIN, 0, 0 ); // Keeps within colour
  5. Thank you ! I have been trying again today, and I checked out the tutorial by Hare again but haven't had luck yet. Whenever I try similar to how they made albino rabbits I get an error. Clut code (I'm sure it's not correct in some way lol) // $clut = new \Imagick(); // $clut->newImage(1, 1, new \Imagick('green')); // $composed_image->clutImage($clut); // $clut->destroy(); // $composed_image->compositeImage("$custom_session->body_colour", Imagick::COMPOSITE_DEFAULT, 0, 0); I have it commented out currently. Error I get:
  6. Hello! I've been playing with ImageMagick for a hobby pet site using the Mysidia script and I have a page working to put together the layers, which is great. but I have an issue where the colorise is making the layers too dark. The layers that get colorised are black by default so colorise is taking that and making the hex/rgb shades darker. Now I know of the clut function to replace colours but I have no idea at all how to utilise it lol. But as my layers to be recoloured are all solid black, I hope using clut could be better than having darker colours than intended. Body colour: Actual intended colour: Here is my code in customgeneratecontroller.php (it's a bit messy with backslashes as I use WAMP and it wouldn't work any other way lmao) public function index(){ $mysidia = Registry::get("mysidia"); $custom_session = $mysidia->db->select("custom", array(), "uid='{$mysidia->user->getID()}'")->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:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\wings\\' . $custom_session->wings . '_colour_back.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\wings\\' . $custom_session->wings . '_lines_' . $custom_session->body . '_back.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\tail\\' . $custom_session->tail . '_colour.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\tail\\' . $custom_session->tail . '_lines_' . $custom_session->body . '.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\ears\\' . $custom_session->ears . '_colour2_back.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\ears\\' . $custom_session->ears . '_colour1_back.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\ears\\' . $custom_session->ears . '_lines_' . $custom_session->body . '_back.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\body\\' . $custom_session->body . '_colour.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\body\\' . $custom_session->body . '_lines.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\ears\\' . $custom_session->ears . '_colour2_front.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\ears\\' . $custom_session->ears . '_colour1_front.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\ears\\' . $custom_session->ears . '_lines_' . $custom_session->body . '_front.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\face\\' . $custom_session->face . '_sclera.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\face\\' . $custom_session->face . '_iris.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\face\\' . $custom_session->face . '_nose.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\face\\' . $custom_session->face . '_lines.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\wings\\' . $custom_session->wings . '_colour_front.png', 'http:\\\\127.0.0.1\\mysidia\\images\\adopts\\' . $custom_session->species . '\\adult\\wings\\' . $custom_session->wings . '_lines_' . $custom_session->body . '_front.png' ); // // This creates the Imagick class that we will use. $composed_image = new \Imagick($images); $composed_image->setIteratorIndex(0); $composed_image->colorizeImage("$custom_session->wings_colour", 1, true); // Colours the back wings $composed_image->setIteratorIndex(2); $composed_image->colorizeImage("$custom_session->body_colour", 1, true); // Colours the tail the same as the body $composed_image->setIteratorIndex(4); $composed_image->colorizeImage("$custom_session->inner_ear_colour", 1, true); // Colours the back inner ear $composed_image->setIteratorIndex(5); $composed_image->colorizeImage("$custom_session->body_colour", 1, true); // Colours the back outer ear the same as the body $composed_image->setIteratorIndex(7); $composed_image->colorizeImage("$custom_session->body_colour", 1, true); // Colours the body $composed_image->setIteratorIndex(9); $composed_image->colorizeImage("$custom_session->inner_ear_colour", 1, true); // Colours the front inner ear $composed_image->setIteratorIndex(10); $composed_image->colorizeImage("$custom_session->body_colour", 1, true); // Colours the front outer ear the same as the body $composed_image->setIteratorIndex(12); $composed_image->colorizeImage("$custom_session->sclera_colour", 1, true); // Colours the sclera $composed_image->setIteratorIndex(13); $composed_image->colorizeImage("$custom_session->iris_colour", 1, true); // Colours the iris $composed_image->setIteratorIndex(14); $composed_image->colorizeImage("$custom_session->nose_colour", 1, true); // Colours the nose $composed_image->setIteratorIndex(16); $composed_image->colorizeImage("$custom_session->wings_colour", 1, true); // Colours the front wings // 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(); } Thank you ! Hopefully someone knows what I should do lol
×
×
  • Create New...